You are here

public function ContextAwarePluginBase::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 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.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Overrides PluginBase::__construct

File

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

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition) {
  $context_configuration = isset($configuration['context']) ? $configuration['context'] : [];
  unset($configuration['context']);
  parent::__construct($configuration, $plugin_id, $plugin_definition);
  if ($context_configuration) {
    @trigger_error('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980', E_USER_DEPRECATED);
  }
  $this->context = $this
    ->createContextFromConfiguration($context_configuration);
}