You are here

public function ContextAwarePluginTrait::setContext in Drupal 9

3 calls to ContextAwarePluginTrait::setContext()
ContextAwarePluginTrait::setContextValue in core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php
DefaultsSectionStorage::setContext in core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php
Set a context on this plugin.
TestContextAwarePlugin::setContext in core/tests/Drupal/KernelTests/Core/Plugin/Context/ContextAwarePluginTraitTest.php
Set a context on this plugin.
1 method overrides ContextAwarePluginTrait::setContext()
DefaultsSectionStorage::setContext in core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php
Set a context on this plugin.

File

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

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;
}