Important

You are browsing documentation for version 5.1 of OroCommerce, supported until March 2026. Read the documentation for version 6.0 (the latest LTS version) to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Post Processors 

A post-processor is a data transformer that converts a field value to a format suitable for the API. Post-processors are used only in the get, get_list and get_subresource actions.

The following table shows all post processors provided out-of-the-box:

Name

Description

Options

twig

Applies a TWIG template.

template string - The name of the TWIG template.

All post processors are registered in PostProcessorRegistry. You can use it when you need to get a specific post processor in your code.

Creating a New Post Processor 

To create a new post processor, you need to do the following:

  1. Create a class that implements PostProcessorInterface.

namespace Acme\Bundle\DemoBundle\Api\PostProcessor;

use Oro\Bundle\ApiBundle\PostProcessor\PostProcessorInterface;

class SomePostProcessor implements PostProcessorInterface
{
    /**
     * {@inheritDoc}
     */
    public function process(mixed $value, array $options): mixed
    {
    }
}
  1. Register the post-processor in the dependency injection container using the oro.api.post_processor tag with the alias attribute that contains a unique name of the post-processor:

acme.api.post_processor.some:
    class: Acme\Bundle\DemoBundle\Api\PostProcessor\SomePostProcessor
    tags:
        - { name: oro.api.post_processor, alias: some }
  1. Create a config extension if you need to validate the post-processor options.

namespace Acme\Bundle\DemoBundle\Api\PostProcessor;

use Oro\Bundle\ApiBundle\Util\ConfigUtil;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

class SomePostProcessorConfigExtension extends AbstractConfigExtension
{
    /**
     * {@inheritDoc}
     */
    public function getConfigureCallbacks(): array
    {
        return [
            'entities.entity.field'                 => function (NodeBuilder $node) {
                $this->addValidationOfPostProcessorOptions($node);
            },
            'actions.action.field'                  => function (NodeBuilder $node) {
                $this->addValidationOfPostProcessorOptions($node);
            },
            'subresources.subresource.action.field' => function (NodeBuilder $node) {
                $this->addValidationOfPostProcessorOptions($node);
            }
        ];
    }

    /**
     * @param NodeBuilder $node
     */
    private function addValidationOfPostProcessorOptions(NodeBuilder $node): void
    {
        $node->end()->validate()
            ->ifTrue(function ($v) {})
            ->thenInvalid();
    }
}
  1. Register the config extension as a service in the dependency injection container.

acme.api.config_extension.post_processor.some:
    class: Acme\Bundle\DemoBundle\Api\PostProcessor\SomePostProcessorConfigExtension
  1. Register the config extension in Resources/config/oro/app.yml in your bundle or config/config.yml of your application.

oro_api:
    config_extensions:
        - acme.api.config_extension.post_processor.some