Annotation for context definition
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\plugin_context
- 10 core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\plugin_context
- 11.x core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\plugin_context
Describes how to use ContextDefinition annotation.
When providing plugin annotations, contexts can be defined to support UI interactions through providing limits, and mapping contexts to appropriate plugins. Context definitions can be provided as such:
context_definitions = {
"node" = @ContextDefinition("entity:node")
}
To add a label to a context definition use the "label" key:
context_definitions = {
"node" = @ContextDefinition("entity:node", label = @Translation("Node"))
}
Contexts are required unless otherwise specified. To make an optional context use the "required" key:
context_definitions = {
"node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node"))
}
To define multiple contexts, simply provide different key names in the context array:
context_definitions = {
"artist" = @ContextDefinition("entity:node", label = @Translation("Artist")),
"album" = @ContextDefinition("entity:node", label = @Translation("Album"))
}
Specifying a default value for the context definition:
context_definitions = {
"message" = @ContextDefinition("string",
label = @Translation("Message"),
default_value = @Translation("Checkout complete! Thank you for your purchase.")
)
}
See also
File
-
core/
lib/ Drupal/ Core/ Annotation/ ContextDefinition.php, line 7
Classes
Title Sort descending | File name | Summary |
---|---|---|
ContextDefinition | core/ |
Defines a context definition annotation object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.