Block Attribute Value Transformers are specialized services that handle the transformation of block attribute values from their raw form into a format suitable for rendering or further processing in templates.
These transformers follow a tagged service pattern in Symfony, allowing for extensibility and type-specific handling of different attribute formats.
The primary purpose of these transformers is to:
- Convert raw block attribute data into usable values
- Enable type-specific transformations for different attribute types (e.g., integer, string, content, etc.)
- Provide a consistent interface for accessing block attribute values
Block attribute value transformers are defined as Symfony services with specific tags. Here's an example of how they are defined:
ErdnaxelaWeb\IbexaDesignIntegration\Transformer\BlockAttribute\IntegerBlockAttributeValueTransformer:
lazy: true
tags:
- { name: 'erdnaxelaweb.ibexa_design_integration.transformer.block_attribute_value', type: 'integer'}Key components:
- Tags: Tagged with
erdnaxelaweb.ibexa_design_integration.transformer.block_attribute_valueto be collected by the tagged iterator - Type: Each transformer has a specific type (e.g., 'integer') that corresponds to the block attribute type it handles
Block attribute transformers must implement the ErdnaxelaWeb\IbexaDesignIntegration\Transformer\BlockAttribute\BlockAttributeValueTransformerInterface which defines the method:
transformAttributeValue(
BlockValue $blockValue,
string $attributeIdentifier,
BlockDefinition $blockDefinition,
array $attributeConfiguration
)This method takes the block value, attribute identifier, block definition, and attribute configuration and returns the transformed value.
These transformers are automatically collected using Symfony's tagged service feature:
$transformers: !tagged_iterator {
tag: 'erdnaxelaweb.ibexa_design_integration.transformer.block_attribute_value',
index_by: 'type'
}The main BlockAttributeValueTransformer service uses this tagged iterator to access all registered transformers and delegates the transformation to the appropriate one based on the attribute type.
The Ibexa Design Integration bundle includes the following block attribute value transformers:
- integer
- string
- url
- text
- richtext
- embed
- checkbox
- multiple
- select
- radio
- locationlist
- contenttypelist
- ezlandingpage
To create a custom transformer for a specific block attribute type:
- Create a class that implements
BlockAttributeValueTransformerInterface - Define the transformation logic in the
transformAttributeValue()method - Register the service with the appropriate tag and type in your services configuration
Example:
App\Transformer\BlockAttribute\CustomBlockAttributeValueTransformer:
lazy: true
tags:
- { name: 'erdnaxelaweb.ibexa_design_integration.transformer.block_attribute_value', type: 'custom_type'}