You are here

public function ContextAwarePluginTrait::setContextMapping in Drupal 10

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

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php, line 104

Class

ContextAwarePluginTrait
Provides a trait to add context-aware functionality to plugins.

Namespace

Drupal\Core\Plugin

Code

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