From 4ce7b776557aa04d5fe2f3a44bdef38bc72e47cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Mon, 2 Mar 2026 16:06:32 +0100 Subject: [PATCH 1/4] IBX-10685: Added information on how to add a custom attribute type to an existing storage definition --- .../AddFloatStorageDefinitionTag.php | 21 +++++++++++++++++++ .../custom_attribute_type/src/Kernel.php | 21 +++++++++++++++++++ docs/pim/create_custom_attribute_type.md | 16 +++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php create mode 100644 code_samples/catalog/custom_attribute_type/src/Kernel.php diff --git a/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php new file mode 100644 index 0000000000..fbb6b10307 --- /dev/null +++ b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php @@ -0,0 +1,21 @@ +getDefinition(StorageDefinition::class) + ->addTag('ibexa.product_catalog.attribute.storage_definition', ['type' => 'percent']); + } +} diff --git a/code_samples/catalog/custom_attribute_type/src/Kernel.php b/code_samples/catalog/custom_attribute_type/src/Kernel.php new file mode 100644 index 0000000000..eeb59b80cf --- /dev/null +++ b/code_samples/catalog/custom_attribute_type/src/Kernel.php @@ -0,0 +1,21 @@ +addCompilerPass(new AddFloatStorageDefinitionTag(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); + } +} diff --git a/docs/pim/create_custom_attribute_type.md b/docs/pim/create_custom_attribute_type.md index 71fd03254f..072532c182 100644 --- a/docs/pim/create_custom_attribute_type.md +++ b/docs/pim/create_custom_attribute_type.md @@ -160,7 +160,9 @@ Register the converter as a service and tag it with `ibexa.product_catalog.attri ### Storage definition -Next, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. +You can either create a new storage definition or use an existing one. + +To create a new one, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. ``` php [[= include_file('code_samples/catalog/custom_attribute_type/src/Attribute/Percent/Storage/PercentStorageDefinition.php') =]] @@ -172,6 +174,18 @@ Register the storage definition as a service and tag it with `ibexa.product_cata [[= include_file('code_samples/catalog/custom_attribute_type/config/custom_services.yaml', 41, 44) =]] ``` +However, if you prefer to use an existing storage definition, you need to create a Storage Definition Tag CompilerPass `src/DependencyInjection/AddFloatStorageDefinitionTag.php`: + +``` php +[[= include_file('code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php') =]] +``` + +Add the CompilerPass to the container with a priority higher than 0 so that it runs first `src/Kernel.php`: + +``` php hl_lines="5 7-8 14-20" +[[= include_file('code_samples/catalog/custom_attribute_type/src/Kernel.php') =]] +``` + ## Use new attribute type In the back office you can now add a new Percent attribute to your product type and create a product with it. From e2143b0712b92e242b6bc2de2ba8f54ac57ca3e0 Mon Sep 17 00:00:00 2001 From: mateuszdebinski Date: Mon, 2 Mar 2026 15:16:30 +0000 Subject: [PATCH 2/4] PHP & JS CS Fixes --- .../src/DependencyInjection/AddFloatStorageDefinitionTag.php | 2 +- code_samples/catalog/custom_attribute_type/src/Kernel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php index fbb6b10307..f9f55fa442 100644 --- a/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php +++ b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php @@ -8,8 +8,8 @@ namespace App\DependencyInjection; use Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageDefinition; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; class AddFloatStorageDefinitionTag implements CompilerPassInterface { diff --git a/code_samples/catalog/custom_attribute_type/src/Kernel.php b/code_samples/catalog/custom_attribute_type/src/Kernel.php index eeb59b80cf..c8110471c5 100644 --- a/code_samples/catalog/custom_attribute_type/src/Kernel.php +++ b/code_samples/catalog/custom_attribute_type/src/Kernel.php @@ -1,4 +1,4 @@ - Date: Tue, 3 Mar 2026 11:48:42 +0100 Subject: [PATCH 3/4] Corrected CS --- code_samples/catalog/custom_attribute_type/src/Kernel.php | 2 +- docs/pim/create_custom_attribute_type.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code_samples/catalog/custom_attribute_type/src/Kernel.php b/code_samples/catalog/custom_attribute_type/src/Kernel.php index eeb59b80cf..b1af1b7ff3 100644 --- a/code_samples/catalog/custom_attribute_type/src/Kernel.php +++ b/code_samples/catalog/custom_attribute_type/src/Kernel.php @@ -16,6 +16,6 @@ public function build(ContainerBuilder $container): void { parent::build($container); - $container->addCompilerPass(new AddFloatStorageDefinitionTag(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10); + $container->addCompilerPass(new AddFloatStorageDefinitionTag()); } } diff --git a/docs/pim/create_custom_attribute_type.md b/docs/pim/create_custom_attribute_type.md index 072532c182..59eae5ebde 100644 --- a/docs/pim/create_custom_attribute_type.md +++ b/docs/pim/create_custom_attribute_type.md @@ -162,7 +162,7 @@ Register the converter as a service and tag it with `ibexa.product_catalog.attri You can either create a new storage definition or use an existing one. -To create a new one, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. +To create a new storage definition, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. ``` php [[= include_file('code_samples/catalog/custom_attribute_type/src/Attribute/Percent/Storage/PercentStorageDefinition.php') =]] @@ -174,13 +174,13 @@ Register the storage definition as a service and tag it with `ibexa.product_cata [[= include_file('code_samples/catalog/custom_attribute_type/config/custom_services.yaml', 41, 44) =]] ``` -However, if you prefer to use an existing storage definition, you need to create a Storage Definition Tag CompilerPass `src/DependencyInjection/AddFloatStorageDefinitionTag.php`: +If you prefer to use an existing storage definition, you need to create a Storage Definition Tag CompilerPass `src/DependencyInjection/AddFloatStorageDefinitionTag.php`: ``` php [[= include_file('code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php') =]] ``` -Add the CompilerPass to the container with a priority higher than 0 so that it runs first `src/Kernel.php`: +Add the CompilerPass to the container. Do it in a `src/Kernel.php` file or in your Bundle class: ``` php hl_lines="5 7-8 14-20" [[= include_file('code_samples/catalog/custom_attribute_type/src/Kernel.php') =]] From d602d73daad877f97a35faa2b938166381e6f27a Mon Sep 17 00:00:00 2001 From: mateuszdebinski Date: Tue, 3 Mar 2026 10:57:42 +0000 Subject: [PATCH 4/4] PHP & JS CS Fixes --- code_samples/catalog/custom_attribute_type/src/Kernel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/code_samples/catalog/custom_attribute_type/src/Kernel.php b/code_samples/catalog/custom_attribute_type/src/Kernel.php index f2f4ac2564..464772c47c 100644 --- a/code_samples/catalog/custom_attribute_type/src/Kernel.php +++ b/code_samples/catalog/custom_attribute_type/src/Kernel.php @@ -4,7 +4,6 @@ use App\DependencyInjection\AddFloatStorageDefinitionTag; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel;