You are here

public function EntityTraversalFactory::getTraversal in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_fields/src/EntityTraversalFactory.php \Drupal\gdpr_fields\EntityTraversalFactory::getTraversal()
  2. 3.0.x modules/gdpr_fields/src/EntityTraversalFactory.php \Drupal\gdpr_fields\EntityTraversalFactory::getTraversal()

Instantiates the traversal class.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Base entity to start recursive traversal.

Return value

\Drupal\gdpr_fields\EntityTraversalInterface Traversal class.

File

modules/gdpr_fields/src/EntityTraversalFactory.php, line 52

Class

EntityTraversalFactory
Factory class for traversing entities.

Namespace

Drupal\gdpr_fields

Code

public function getTraversal(EntityInterface $entity) {
  $traversal_class = $this->traverser;
  $class = new ReflectionClass($traversal_class);
  if ($class
    ->implementsInterface(EntityTraversalInterface::class)) {

    /* @var \Drupal\gdpr_fields\EntityTraversalInterface $instance */
    $instance = $traversal_class::create($this->container, $entity);
    return $instance;
  }

  // @todo Handle exceptions?
}