ChainEntityResolver.php

Same filename in other branches
  1. 9 core/modules/serialization/src/EntityResolver/ChainEntityResolver.php
  2. 8.9.x core/modules/serialization/src/EntityResolver/ChainEntityResolver.php
  3. 10 core/modules/serialization/src/EntityResolver/ChainEntityResolver.php

Namespace

Drupal\serialization\EntityResolver

File

core/modules/serialization/src/EntityResolver/ChainEntityResolver.php

View source
<?php

namespace Drupal\serialization\EntityResolver;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
 * Resolver delegating the entity resolution to a chain of resolvers.
 */
class ChainEntityResolver implements ChainEntityResolverInterface {
    
    /**
     * The concrete resolvers.
     *
     * @var \Drupal\serialization\EntityResolver\EntityResolverInterface[]
     */
    protected $resolvers = [];
    
    /**
     * Constructs a ChainEntityResolver object.
     *
     * @param \Drupal\serialization\EntityResolver\EntityResolverInterface[] $resolvers
     *   The array of concrete resolvers.
     */
    public function __construct(array $resolvers = []) {
        $this->resolvers = $resolvers;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addResolver(EntityResolverInterface $resolver) {
        $this->resolvers[] = $resolver;
    }
    
    /**
     * {@inheritdoc}
     */
    public function resolve(NormalizerInterface $normalizer, $data, $entity_type) {
        foreach ($this->resolvers as $resolver) {
            $resolved = $resolver->resolve($normalizer, $data, $entity_type);
            if (isset($resolved)) {
                return $resolved;
            }
        }
    }

}

Classes

Title Deprecated Summary
ChainEntityResolver Resolver delegating the entity resolution to a chain of resolvers.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.