Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / ctools / src / ContextMapper.php
1 <?php
2
3 namespace Drupal\ctools;
4
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;
9
10 /**
11  * Maps context configurations to context objects.
12  */
13 class ContextMapper implements ContextMapperInterface {
14
15   /**
16    * The entity repository.
17    *
18    * @var \Drupal\Core\Entity\EntityRepositoryInterface
19    */
20   protected $entityRepository;
21
22   /**
23    * Constructs a new ContextMapper.
24    *
25    * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
26    *   The entity repository.
27    */
28   public function __construct(EntityRepositoryInterface $entity_repository) {
29     $this->entityRepository = $entity_repository;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getContextValues(array $context_configurations) {
36     $contexts = [];
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']);
41       }
42       else {
43         $context = new Context($context_definition, $context_configuration['value']);
44       }
45       $contexts[$name] = $context;
46     }
47     return $contexts;
48   }
49
50 }