flex_processor
38 sites
No security coverage
Flex Processor is a versatile Drupal module designed to empower developers with the ability to seamlessly attach customizable processor plugins to various data structures. This tool allows developers to define specific processing workflows for their data, enabling dynamic manipulation and transformation.
Features
Key Features:
- Customizable Processors: Easily create and attach processors tailored to unique data needs, providing flexibility in data handling.
- Data Manipulation: Reduce, modify, update, or transform data as required, ensuring the output meets specific requirements.
- API Response Structuring: Streamline API responses by processing the output efficiently, enhancing integration and performance.
- Context-Agnostic Application: While optimized for API use, Flex Processor can be applied in diverse contexts where data transformation is necessary.
- Developer-Friendly: Simplifies the development process, allowing quick definitions of processor logic without extensive overhead.
- With Flex Process, developers gain a powerful tool that enhances data flexibility and responsiveness, making it easier to create robust, adaptable
Post-Installation
After installing the module, you will be able to create processors plugins and process data with them
<?php
namespace Drupal\your_module\Plugin\EntityDataProcessor;
use Drupal\flex_processor\Plugin\EntityDataProcessor;
/**
* Returns the structured data of an entity.
*
* @DataProcessor(
* id = "node__article__card",
* label = @Translation("Node: Article Card"),
* type = "node",
* bundles = {
* "article"
* },
* variant = "card"
* )
*/
class ArticleCard extends EntityDataProcessor {
/**
* {@inheritdoc}
*/
public function process(mixed $entity, array $options = []): mixed {
return [
'title' => $entity->getTitle(),
'type' => $entity->getType(),
'url' => $entity->toUrl()->toString(TRUE)->getGeneratedUrl(),
'fields' => [
'summary' => $this->dataProcessorManager->process(
$entity->get('body'),
),
'image' => $this->dataProcessorManager->process(
$entity->get('field_media'),
['style' => 'article_card_400x300'],
)
]
];
}
}
And this processor can be trigger with
<?php
$article = \Drupal::entityTypeManager()->getStorage('node')->load($aid);
$data = \Drupal::service('plugin.manager.flex_processor')->process(
$article,
['variant' => 'card'],
);
echo json_encode($data);
output
{
"title" : "Title A",
"type" : "article",
"url" : "https://example.com/article/title-a",
"fields" : {
"summary" : "Bla bla bla bla...",
"image" : "https://example.com/site/default/files/styles/article_card_400x300/public/2024-10/image-a.png",
}
}
Read the readme.md file for more examples