3 namespace Drupal\ctools;
5 use Drupal\Core\Entity\EntityRepositoryInterface;
6 use Drupal\Core\Plugin\Context\Context;
7 use Drupal\Core\Plugin\Context\ContextDefinition;
8 use Drupal\ctools\Context\EntityLazyLoadContext;
11 * Maps context configurations to context objects.
13 class ContextMapper implements ContextMapperInterface {
16 * The entity repository.
18 * @var \Drupal\Core\Entity\EntityRepositoryInterface
20 protected $entityRepository;
23 * Constructs a new ContextMapper.
25 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
26 * The entity repository.
28 public function __construct(EntityRepositoryInterface $entity_repository) {
29 $this->entityRepository = $entity_repository;
35 public function getContextValues(array $context_configurations) {
37 foreach ($context_configurations as $name => $context_configuration) {
38 $context_definition = new ContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
39 if (strpos($context_configuration['type'], 'entity:') === 0) {
40 $context = new EntityLazyLoadContext($context_definition, $this->entityRepository, $context_configuration['value']);
43 $context = new Context($context_definition, $context_configuration['value']);
45 $contexts[$name] = $context;