You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 13, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: docs/backend/cookbook/new_attribute.md
+59-26Lines changed: 59 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,9 @@ This file should live in `Your-module\Application\Form\Attribute\` namespace ext
12
12
In Ergonode system we have several Abstract Attribute classes (you can find them in `Ergonode\Attribute\Domain\Entity\Attribute` namespace), it depends on what kind of attribute you want to create, you can either use one of already created or create a custom one.
13
13
14
14
Keep in mind that Abstract Attribute class should extend `\Ergonode\Attribute\Domain\Entity\AbstractAttribute`.
@@ -22,7 +23,7 @@ class YourAttribute extends AbstractCollectionAttribute implements AttributeInte
22
23
public const TYPE = 'YOUR_ATTRIBUTE';
23
24
24
25
/**
25
-
* @JMS\virtualProperty();
26
+
* @JMS\VirtualProperty();
26
27
* @JMS\SerializedName("type")
27
28
*
28
29
* @return string
@@ -42,7 +43,7 @@ Create a command for creation `CreateYourAttributeCommand`.
42
43
This file should live in `Your-module\Domain\Command\Attribute\Create` namespace and extends `Ergonode\Attribute\Domain\Command\Attribute\AbstractCreateAttributeCommand`.
@@ -104,7 +106,7 @@ class CreateYourAttributeCommandHandler
104
106
Create a command for update `UpdateYourAttributeCommand`.This file should live in `Your-module\Domain\Command\Attribute\Update` namespace and extends `Ergonode\Attribute\Domain\Command\Attribute\AbstractUpdateAttributeCommand`.
@@ -154,11 +157,11 @@ class UpdateYourAttributeCommandHandler extends AbstractUpdateAttributeCommandHa
154
157
155
158
## Command factories
156
159
157
-
Create a handler for creation command `CreateYourAttributeCommandFactory`.This file should live in `Your-module\Infrastructure\Factory\Command\Create` namespace and implements `Ergonode\Attribute\Infrastructure\Factory\Command\CreateAttributeCommandFactoryInterface`
158
-
160
+
Create a handler for creation command `CreateYourAttributeCommandFactory`.This file should live in `Your-module\Infrastructure\Factory\Command\Create` namespace and implements `Ergonode\Attribute\Infrastructure\Factory\Command\CreateAttributeCommandFactoryInterface`
161
+
If autoconfiguration is not used remember to tag your service with `component.attribute.create_attribute_command_factory_interface`
@@ -199,9 +202,10 @@ class CreateYourAttributeCommandFactory implements CreateAttributeCommandFactory
199
202
```
200
203
201
204
Create a handler for updating command `UpdateYourAttributeCommandFactory`.This file should live in `Your-module\Infrastructure\Factory\Command\Update` namespace and implements `Ergonode\Attribute\Infrastructure\Factory\Command\UpdateAttributeCommandFactoryInterface`
205
+
If autoconfiguration is not used remember to tag your service with `component.attribute.update_attribute_command_factory_interface`
@@ -235,7 +239,7 @@ class UpdateYourAttributeCommandFactory implements UpdateAttributeCommandFactory
235
239
new TranslatableString($data->hint),
236
240
new TranslatableString($data->placeholder),
237
241
new AttributeScope($data->scope),
238
-
$data->groups,
242
+
array_map(fn($group) => new AttributeGroupId($group), $data->groups),
239
243
);
240
244
}
241
245
}
@@ -244,12 +248,11 @@ class UpdateYourAttributeCommandFactory implements UpdateAttributeCommandFactory
244
248
## Value Constrain Strategy
245
249
246
250
To be able to validate values which are used in our new attribute `YourAttributeValueConstraintStrategy` needs to be created. This file should live in `Your-module\Infrastructure\Provider\Strategy` namespace and implements `Ergonode\Attribute\Infrastructure\Provider\AttributeValueConstraintStrategyInterface`
251
+
If autoconfiguration is not used remember to tag your service with `component.attribute.attribute_validation_interface`
class YourAttributeForm extends AbstractType implements AttributeFormInterface
291
295
{
@@ -358,12 +362,36 @@ class YourAttributeForm extends AbstractType implements AttributeFormInterface
358
362
359
363
If you want be able to use your attribute on a grid you need to create following classes.
360
364
365
+
366
+
Create column class `YourAttributeColumn`
367
+
368
+
This file should live in `Your-module\Grid\Column` namespace and extends `\Ergonode\Grid\Column\AbstractColumn`
369
+
370
+
```php
371
+
namespace YourNameSpace\Grid\Column;
372
+
373
+
/**
374
+
*/
375
+
class YourColumn extends AbstractColumn
376
+
{
377
+
public const TYPE = 'YOUR_ATTRIBUTE';
378
+
379
+
/**
380
+
* {@inheritDoc}
381
+
*/
382
+
public function getType(): string
383
+
{
384
+
return self::TYPE;
385
+
}
386
+
}
387
+
```
388
+
361
389
Create strategy class `YourAttributeColumnStrategy`
362
390
363
391
This file should live in `Your-module\Infrastructure\Grid\Column\Provider\Strategy` namespace and implements `Ergonode\Product\Infrastructure\Grid\Column\Provider\Strategy\AttributeColumnStrategyInterface`
@@ -395,7 +423,7 @@ Create DataSet Builder class `YourAttributeDataSetQueryBuilder`
395
423
This file should live in `Your-module\Infrastructure\Grid\Builder\Query` namespace and extends `Ergonode\Product\Infrastructure\Grid\Builder\Query\AbstractAttributeDataSetBuilder`
Any custom mass action process must implement ```BatchActionProcessorInterface```
6
+
7
+
```php
8
+
namespace YourNameSpace\Infrastructure\Processor;
9
+
10
+
use Ergonode\BatchAction\Domain\Entity\BatchActionId;
11
+
use Ergonode\BatchAction\Domain\ValueObject\BatchActionMessage;
12
+
use Ergonode\BatchAction\Domain\ValueObject\BatchActionType;
13
+
use Ergonode\BatchAction\Infrastructure\Provider\BatchActionProcessorInterface;
14
+
use Ergonode\SharedKernel\Domain\AggregateId;
15
+
16
+
class YourBatchActionProcessor implements BatchActionProcessorInterface
17
+
{
18
+
public function supports(BatchActionType $type): bool
19
+
{
20
+
return $type->getValue() === 'you type';
21
+
}
22
+
23
+
/**
24
+
* @return BatchActionMessage[]
25
+
*/
26
+
public function process(BatchActionId $id, AggregateId $resourceId): array
27
+
{
28
+
// here implement your action for given AggregateId
29
+
}
30
+
}
31
+
```
32
+
33
+
If, for some reason, a mass action can't be processed for a given object, you can return information about it as array of ```BatchActionMessage``` objects
34
+
In whole batch action this object is marked processed as unsuccessful.
0 commit comments