You are here

public function ContextAwarePluginBase::setContextMapping in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php \Drupal\Core\Plugin\ContextAwarePluginBase::setContextMapping()

Sets a mapping of the expected assignment names to their context names.

Parameters

array $context_mapping: A mapping of the expected assignment names to their context names. For example, if one of the $contexts is named 'user.current_user', but the plugin expects a context named 'user', then this map would contain 'user' => 'user.current_user'.

Return value

$this

Overrides ContextAwarePluginInterface::setContextMapping

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 93
Contains \Drupal\Core\Plugin\ContextAwarePluginBase.

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Core\Plugin

Code

public function setContextMapping(array $context_mapping) {
  if ($this instanceof ConfigurablePluginInterface) {
    $configuration = $this
      ->getConfiguration();
    $configuration['context_mapping'] = array_filter($context_mapping);
    $this
      ->setConfiguration($configuration);
  }
  else {
    $this->configuration['context_mapping'] = $context_mapping;
  }
  return $this;
}