You are here

public function Context::getContextValue in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/Plugin/Context/Context.php \Drupal\Component\Plugin\Context\Context::getContextValue()

Gets the context value.

Return value

mixed The currently set context value, or NULL if it is not set.

Overrides ContextInterface::getContextValue

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

File

lib/Drupal/Component/Plugin/Context/Context.php, line 49
Contains \Drupal\Component\Plugin\Context\Context.

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