You are here

class ContextMapper in Page Manager 8.4

Same name and namespace in other branches
  1. 8 src/ContextMapper.php \Drupal\page_manager\ContextMapper

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'
page_manager.services.yml in ./page_manager.services.yml
page_manager.services.yml
1 service uses ContextMapper
page_manager.context_mapper in ./page_manager.services.yml
Drupal\page_manager\ContextMapper

File

src/ContextMapper.php, line 13

Namespace

Drupal\page_manager
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) {
      $context_definition = ContextDefinitionFactory::create($context_configuration['type'])
        ->setLabel($context_configuration['label']);
      if (strpos($context_configuration['type'], 'entity:') === 0) {
        $context = new EntityLazyLoadContext($context_definition, $this->entityRepository, $context_configuration['value']);
      }
      else {
        $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.