Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Content Translation Redirect Module content_translation_redirect crossed 1,000 active installs.

Flex Processor

101 sites No security coverage
View on drupal.org

Flex Processor is a Drupal module that allows developers to attach customizable processing plugins to various data structures. This enables dynamic manipulation and transformation of data, streamlining API responses and simplifying development by allowing quick definitions of processor logic.

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

Activity

Total releases
2
First release
Jun 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Release date
1.0.0-beta4 Pre-release Jun 13, 2025
1.0.0-beta3 Pre-release Jun 12, 2025