You are here

class ChainEntityResolver in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/serialization/src/EntityResolver/ChainEntityResolver.php \Drupal\serialization\EntityResolver\ChainEntityResolver
  2. 10 core/modules/serialization/src/EntityResolver/ChainEntityResolver.php \Drupal\serialization\EntityResolver\ChainEntityResolver

Resolver delegating the entity resolution to a chain of resolvers.

Hierarchy

Expanded class hierarchy of ChainEntityResolver

1 file declares its use of ChainEntityResolver
ChainEntityResolverTest.php in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
1 string reference to 'ChainEntityResolver'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses ChainEntityResolver
serializer.entity_resolver in core/modules/serialization/serialization.services.yml
Drupal\serialization\EntityResolver\ChainEntityResolver

File

core/modules/serialization/src/EntityResolver/ChainEntityResolver.php, line 10

Namespace

Drupal\serialization\EntityResolver
View source
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;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ChainEntityResolver::$resolvers protected property The concrete resolvers.
ChainEntityResolver::addResolver public function Adds an entity resolver. Overrides ChainEntityResolverInterface::addResolver
ChainEntityResolver::resolve public function Returns the local ID of an entity referenced by serialized data. Overrides EntityResolverInterface::resolve
ChainEntityResolver::__construct public function Constructs a ChainEntityResolver object.