public function ContextAwarePluginBase::__construct

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php \Drupal\Core\Plugin\ContextAwarePluginBase::__construct()
  2. 8.x drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase::__construct()

Overrides \Drupal\Component\Plugin\PluginBase::__construct().

Overrides the construction of context aware plugins to allow for unvalidated constructor based injection of contexts.

Parameters

array $configuration: The plugin configuration, i.e. an array with configuration values keyed by configuration option name. The special key 'context' may be used to initialize the defined contexts by setting it to an array of context values keyed by context names.

Overrides PluginBase::__construct

1 call to ContextAwarePluginBase::__construct()
1 method overrides ContextAwarePluginBase::__construct()

File

drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php, line 39
Contains \Drupal\Component\Plugin\ContextAwarePluginBase

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
  $context = array();
  if (isset($configuration['context'])) {
    $context = $configuration['context'];
    unset($configuration['context']);
  }
  parent::__construct($configuration, $plugin_id, $plugin_definition);
  foreach ($context as $key => $value) {
    $context_definition = $this
      ->getContextDefinition($key);
    $this->context[$key] = new Context($context_definition);
    $this->context[$key]
      ->setContextValue($value);
  }
}