You are here

public function ContextAwarePluginBase::getContext in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase::getContext()

Gets a defined context.

Parameters

string $name: The name of the context in the plugin definition.

Return value

\Drupal\Component\Plugin\Context\ContextInterface The context object.

Throws

\Drupal\Component\Plugin\Exception\ContextException If the requested context is not set.

Overrides ContextAwarePluginInterface::getContext

1 call to ContextAwarePluginBase::getContext()
ContextAwarePluginBase::getContexts in core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php
Gets the defined contexts.

File

core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php, line 112

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function getContext($name) {

  // Check for a valid context value.
  if (!isset($this->context[$name])) {
    $this->context[$name] = new Context($this
      ->getContextDefinition($name));
  }
  return $this->context[$name];
}