-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
47 lines (36 loc) · 1.32 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Flamarkt\ProductSlugs;
use Flamarkt\Core\Api\Serializer\BasicProductSerializer;
use Flamarkt\Core\Product\Event\Saving;
use Flamarkt\Core\Product\Product;
use Flamarkt\Core\Product\ProductValidator;
use Flarum\Extend;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
return [
(new Extend\Frontend('backoffice'))
->js(__DIR__ . '/js/dist/backoffice.js'),
new Extend\Locales(__DIR__ . '/resources/locale'),
(new Extend\Event())
->listen(Saving::class, Listeners\SaveProduct::class),
(new Extend\ApiSerializer(BasicProductSerializer::class))
->attributes(ProductAttributes::class),
(new Extend\ModelUrl(Product::class))
->addSlugDriver('slug', SlugDriver::class),
(new Extend\Validator(ProductValidator::class))
->configure(function (ProductValidator $flarumValidator, Validator $validator) {
$rule = Rule::unique('flamarkt_products', 'slug');
$product = $flarumValidator->getProduct();
if ($product) {
$rule->ignore($product);
}
$validator->addRules([
'slug' => [
'nullable',
'regex:/^[a-z0-9_-]+$/i',
'max:255',
$rule,
],
]);
}),
];