class OptionalContextCondition

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php \Drupal\condition_test\Plugin\Condition\OptionalContextCondition
  2. 10 core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php \Drupal\condition_test\Plugin\Condition\OptionalContextCondition
  3. 8.9.x core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php \Drupal\condition_test\Plugin\Condition\OptionalContextCondition

Provides a condition with an optional node context.

The context type entity:node is used since that would allow to also use this for web tests with the node route context.

Plugin annotation


@Condition(
  id = "condition_test_optional_context",
  label = @Translation("Optional context"),
  context_definitions = {
    "node" = @ContextDefinition("entity:node", label = @Translation("Node"), required = FALSE),
  }
)

Hierarchy

Expanded class hierarchy of OptionalContextCondition

File

core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php, line 21

Namespace

Drupal\condition_test\Plugin\Condition
View source
class OptionalContextCondition extends ConditionPluginBase {
  
  /**
   * {@inheritdoc}
   */
  public function evaluate() {
    // Grant access if no context value is given.
    return !$this->getContextValue('node');
  }
  
  /**
   * {@inheritdoc}
   */
  public function summary() {
    return $this->t('Context with optional context.');
  }

}

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