class ContextMapper in Page Manager 8
Same name and namespace in other branches
- 8.4 src/ContextMapper.php \Drupal\page_manager\ContextMapper
Maps context configurations to context objects.
Hierarchy
- class \Drupal\page_manager\ContextMapper implements ContextMapperInterface
Expanded class hierarchy of ContextMapper
1 file declares its use of ContextMapper
- ContextMapperTest.php in tests/src/ Unit/ ContextMapperTest.php 
- Contains \Drupal\Tests\page_manager\Unit\ContextMapperTest.
1 string reference to 'ContextMapper'
1 service uses ContextMapper
File
- src/ContextMapper.php, line 18 
- Contains \Drupal\page_manager\ContextMapper.
Namespace
Drupal\page_managerView 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 = new ContextDefinition($context_configuration['type'], $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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| ContextMapper:: | protected | property | The entity repository. | |
| ContextMapper:: | public | function | Gathers the static context values. Overrides ContextMapperInterface:: | |
| ContextMapper:: | public | function | Constructs a new ContextMapper. | 
