class OptionalContextCondition in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php \Drupal\condition_test\Plugin\Condition\OptionalContextCondition
- 9 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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Executable\ExecutablePluginBase implements CacheableDependencyInterface, ExecutableInterface, ContextAwarePluginInterface uses ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase implements ConditionInterface uses ContextAwarePluginAssignmentTrait
- class \Drupal\condition_test\Plugin\Condition\OptionalContextCondition
- class \Drupal\Core\Condition\ConditionPluginBase implements ConditionInterface uses ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase implements CacheableDependencyInterface, ExecutableInterface, ContextAwarePluginInterface uses ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
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\ConditionView 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.');
}
}