You are here

class EntityTraversalFactory in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_fields/src/EntityTraversalFactory.php \Drupal\gdpr_fields\EntityTraversalFactory
  2. 3.0.x modules/gdpr_fields/src/EntityTraversalFactory.php \Drupal\gdpr_fields\EntityTraversalFactory

Factory class for traversing entities.

@package Drupal\gdpr_fields

Hierarchy

Expanded class hierarchy of EntityTraversalFactory

2 files declare their use of EntityTraversalFactory
Anonymizer.php in modules/gdpr_tasks/src/Anonymizer.php
GdprTasksSarWorker.php in modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php
1 string reference to 'EntityTraversalFactory'
gdpr_tasks.services.yml in modules/gdpr_tasks/gdpr_tasks.services.yml
modules/gdpr_tasks/gdpr_tasks.services.yml
4 services use EntityTraversalFactory
gdpr_tasks.rta_display_traversal in modules/gdpr_tasks/gdpr_tasks.services.yml
Drupal\gdpr_fields\EntityTraversalFactory
gdpr_tasks.rta_traversal in modules/gdpr_tasks/gdpr_tasks.services.yml
Drupal\gdpr_fields\EntityTraversalFactory
gdpr_tasks.rtf_display_traversal in modules/gdpr_tasks/gdpr_tasks.services.yml
Drupal\gdpr_fields\EntityTraversalFactory
gdpr_tasks.rtf_traversal in modules/gdpr_tasks/gdpr_tasks.services.yml
Drupal\gdpr_fields\EntityTraversalFactory

File

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

Namespace

Drupal\gdpr_fields
View source
class EntityTraversalFactory {

  /**
   * The service container.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * The traversal class name to be instantiated.
   *
   * @var string
   */
  protected $traverser;

  /**
   * EntityTraversal constructor.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The service container.
   * @param string $traverser
   *   The traversal class name.
   */
  public function __construct(ContainerInterface $container, $traverser) {
    $this->container = $container;
    $this->traverser = $traverser;
  }

  /**
   * Instantiates the traversal class.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   Base entity to start recursive traversal.
   *
   * @return \Drupal\gdpr_fields\EntityTraversalInterface
   *   Traversal class.
   */
  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?
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityTraversalFactory::$container protected property The service container.
EntityTraversalFactory::$traverser protected property The traversal class name to be instantiated.
EntityTraversalFactory::getTraversal public function Instantiates the traversal class.
EntityTraversalFactory::__construct public function EntityTraversal constructor.