You are here

public function ContextAwarePluginTrait::setContext in Drupal 10

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

File

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

Class

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

Namespace

Drupal\Core\Plugin

Code

public function setContext($name, ComponentContextInterface $context) {

  // Check that the context passed is an instance of our extended interface.
  if (!$context instanceof ContextInterface) {
    throw new ContextException("Passed {$name} context must be an instance of \\Drupal\\Core\\Plugin\\Context\\ContextInterface");
  }
  $this->context[$name] = $context;
}