function Context::getContextValue

Same name in this branch
  1. 10 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::getContextValue()
Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::getContextValue()
  2. 9 core/lib/Drupal/Component/Plugin/Context/Context.php \Drupal\Component\Plugin\Context\Context::getContextValue()
  3. 8.9.x core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::getContextValue()
  4. 8.9.x core/lib/Drupal/Component/Plugin/Context/Context.php \Drupal\Component\Plugin\Context\Context::getContextValue()
  5. 11.x core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::getContextValue()
  6. 11.x core/lib/Drupal/Component/Plugin/Context/Context.php \Drupal\Component\Plugin\Context\Context::getContextValue()

Overrides ContextInterface::getContextValue

1 call to Context::getContextValue()
Context::validate in core/lib/Drupal/Component/Plugin/Context/Context.php
Validates the set context value.
1 method overrides Context::getContextValue()
Context::getContextValue in core/lib/Drupal/Core/Plugin/Context/Context.php
Gets the context value.

File

core/lib/Drupal/Component/Plugin/Context/Context.php, line 44

Class

Context
A generic context class for wrapping data a plugin needs to operate.

Namespace

Drupal\Component\Plugin\Context

Code

public function getContextValue() {
    // Support optional contexts.
    if (!isset($this->contextValue)) {
        $definition = $this->getContextDefinition();
        $default_value = $definition->getDefaultValue();
        if (!isset($default_value) && $definition->isRequired()) {
            $type = $definition->getDataType();
            throw new ContextException(sprintf("The %s context is required and not present.", $type));
        }
        // Keep the default value here so that subsequent calls don't have to look
        // it up again.
        $this->contextValue = $default_value;
    }
    return $this->contextValue;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.