You are here

class ContextMapper in Chaos Tool Suite (ctools) 8.3

Maps context configurations to context objects.

Hierarchy

Expanded class hierarchy of ContextMapper

1 file declares its use of ContextMapper
ContextMapperTest.php in tests/src/Unit/ContextMapperTest.php
1 string reference to 'ContextMapper'
ctools.services.yml in ./ctools.services.yml
ctools.services.yml
1 service uses ContextMapper
ctools.context_mapper in ./ctools.services.yml
Drupal\ctools\ContextMapper

File

src/ContextMapper.php, line 14

Namespace

Drupal\ctools
View source
class ContextMapper implements ContextMapperInterface {

  /**
   * The entity repository.
   *
   * @var \Drupal\Core\Entity\EntityRepositoryInterface
   */
  protected $entityRepository;

  /**
   * Constructs a new ContextMapper.
   *
   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
   *   The entity repository.
   */
  public function __construct(EntityRepositoryInterface $entity_repository) {
    $this->entityRepository = $entity_repository;
  }

  /**
   * {@inheritdoc}
   */
  public function getContextValues(array $context_configurations) {
    $contexts = [];
    foreach ($context_configurations as $name => $context_configuration) {
      if (strpos($context_configuration['type'], 'entity:') === 0) {
        $context_definition = new EntityContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
        $context = new EntityLazyLoadContext($context_definition, $this->entityRepository, $context_configuration['value']);
      }
      else {
        $context_definition = new ContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
        $context = new Context($context_definition, $context_configuration['value']);
      }
      $contexts[$name] = $context;
    }
    return $contexts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContextMapper::$entityRepository protected property The entity repository.
ContextMapper::getContextValues public function Gathers the static context values. Overrides ContextMapperInterface::getContextValues
ContextMapper::__construct public function Constructs a new ContextMapper.