You are here

class ChainEntityResolver in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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

2 files declare their use of ChainEntityResolver
ChainEntityResolverTest.php in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Contains \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest.
NormalizerTestBase.php in core/modules/hal/src/Tests/NormalizerTestBase.php
Contains \Drupal\hal\Tests\NormalizerTestBase.
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 15
Contains \Drupal\serialization\EntityResolver\ChainEntityResolver.

Namespace

Drupal\serialization\EntityResolver
View source
class ChainEntityResolver implements ChainEntityResolverInterface {

  /**
   * The concrete resolvers.
   *
   * @var \Drupal\serialization\EntityResolver\EntityResolverInterface[]
   */
  protected $resolvers = array();

  /**
   * Constructs a ChainEntityResolver object.
   *
   * @param \Drupal\serialization\EntityResolver\EntityResolverInterface[] $resolvers
   *   The array of concrete resolvers.
   */
  public function __construct(array $resolvers = array()) {
    $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.