function ContextMapper::getContextValues

Same name and namespace in other branches
  1. 4.0.x src/ContextMapper.php \Drupal\ctools\ContextMapper::getContextValues()

Overrides ContextMapperInterface::getContextValues

File

src/ContextMapper.php, line 36

Class

ContextMapper
Maps context configurations to context objects.

Namespace

Drupal\ctools

Code

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;
}