You are here

public function ContextAwarePluginBase::setContextMapping in Drupal 8

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

1 call to ContextAwarePluginBase::setContextMapping()
ConditionPluginBase::submitConfigurationForm in core/lib/Drupal/Core/Condition/ConditionPluginBase.php
Form submission handler.

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 88

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Core\Plugin

Code

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