Annotations
Same name and namespace in other branches
- 8.9.x core/core.api.php \annotation
- 10 core/core.api.php \annotation
- 11.x core/core.api.php \annotation
Annotations for class discovery and metadata description.
The Drupal plugin system has a set of reusable components that developers can use, override, and extend in their modules. Most of the plugins use annotations, which let classes register themselves as plugins and describe their metadata. (Annotations can also be used for other purposes, though at the moment, Drupal only uses them for the plugin system.)
To annotate a class as a plugin, add code similar to the following to the end of the documentation block immediately preceding the class declaration:
* @ContentEntityType(
* id = "comment",
* label = @Translation("Comment"),
* ...
* base_table = "comment"
* )
Note that you must use double quotes; single quotes will not work in annotations.
Some annotation types, which extend the "@ PluginID" annotation class, have only a single 'id' key in their annotation. For these, it is possible to use a shorthand annotation. For example:
* @ViewsArea("entity")
in place of
* @ViewsArea(
* id = "entity"
*)
The available annotation classes are listed in this topic, and can be identified when you are looking at the Drupal source code by having "@ Annotation" in their documentation blocks (without the space after @). To find examples of annotation for a particular annotation class, such as EntityType, look for class files that have an @ annotation section using the annotation class.
See also
Annotation for translatable text
Annotation for context definition
File
-
core/
core.api.php, line 1855
Classes
Title Sort descending | File name | Summary |
---|---|---|
Action | core/ |
Defines an Action annotation object. |
AnnotationEnum | core/ |
Plugin annotation @Target("ALL"); |
AnnotationEnumInvalid | core/ |
Plugin annotation @Target("ALL"); |
AnnotationEnumLiteral | core/ |
Plugin annotation @Target("ALL"); |
AnnotationEnumLiteralInvalid | core/ |
Plugin annotation @Target("ALL"); |
AnnotationExtendsAnnotationTargetAll | core/ |
|
AnnotationTargetAll | core/ |
Plugin annotation @Target("ALL"); |
AnnotationTargetAnnotation | core/ |
Plugin annotation @Target({ "ANNOTATION" }) |
AnnotationTargetClass | core/ |
Plugin annotation @Target("CLASS"); |
AnnotationTargetPropertyMethod | core/ |
Plugin annotation @Target({ "METHOD", "PROPERTY" }) |
AnnotationWithAttributes | core/ |
Plugin annotation @Target("ALL") @Attributes({ @Attribute("mixed", type = "mixed"), @Attribute("boolean", type = "boolean"), @Attribute("bool", type = "bool"), @Attribute("float", … |
AnnotationWithConstants | core/ |
Plugin annotation @Target("ALL"); |
AnnotationWithInvalidTargetDeclaration | core/ |
Plugin annotation @Target("Foo"); |
AnnotationWithRequiredAttributes | core/ |
Plugin annotation @Target("ALL") @Attributes({ @Attribute("value", required = true , type = "string"), @Attribute("annot", required = true , type =… |
AnnotationWithRequiredAttributesWithoutContructor | core/ |
Plugin annotation @Target("ALL"); |
AnnotationWithTargetEmpty | core/ |
@Target |
AnnotationWithTargetSyntaxError | core/ |
Plugin annotation @Target(@) |
AnnotationWithVarType | core/ |
Plugin annotation @Target("ALL"); |
AnnotWithDefaultValue | core/ |
|
Archiver | core/ |
Defines an archiver annotation object. |
Autoload | core/ |
|
Block | core/ |
Defines a Block annotation object. |
Condition | core/ |
Defines a condition plugin annotation object. |
ConfigEntityType | core/ |
Defines a config entity type annotation object. |
Constraint | core/ |
Defines a validation constraint annotation object. |
ContentEntityType | core/ |
Defines a content entity type annotation object. |
ContextDefinition | core/ |
Defines a context definition annotation object. |
CustomPlugin | core/ |
Custom plugin annotation. |
CustomPlugin2 | core/ |
Custom plugin annotation. |
DataType | core/ |
Defines a data type annotation object. |
DisplayVariant | core/ |
Defines a display variant annotation object. |
Editor | core/ |
Defines an Editor annotation object. |
Entity | core/ |
|
Entity | core/ |
This class is a near-copy of tests/Doctrine/Tests/Common/Annotations/Ticket/DCOM58Entity.php, which is part of the Doctrine project: <http://www.doctrine-project.org>. It was copied from version 1.2.7. |
EntityReferenceSelection | core/ |
Defines an EntityReferenceSelection plugin annotation object. |
EntityType | core/ |
Defines an Entity type annotation object. |
FieldFormatter | core/ |
Defines a FieldFormatter annotation object. |
FieldType | core/ |
Defines a FieldType annotation object. |
FieldWidget | core/ |
Defines a FieldWidget annotation object. |
FormElement | core/ |
Defines a form element plugin annotation object. |
ImageToolkit | core/ |
Defines a Plugin annotation object for the image toolkit plugin. |
ImageToolkitOperation | core/ |
Defines a Plugin annotation object for the image toolkit operation plugin. |
Layout | core/ |
Defines a Layout annotation object. |
core/ |
Defines a Mail annotation object. | |
Marker | core/ |
|
Name | core/ |
|
PageDisplayVariant | core/ |
Defines a page display variant annotation object. |
Plugin | core/ |
Defines a Plugin annotation object. |
PluginID | core/ |
Defines a Plugin annotation object that just contains an ID. |
PluralTranslation | core/ |
Defines an annotation object for strings that require plural forms. |
QueueWorker | core/ |
Declare a worker class for processing a queue item. |
RenderElement | core/ |
Defines a render element plugin annotation object. |
Route | core/ |
|
Secure | core/ |
|
SettingsAnnotation | core/ |
|
SomeAnnotationClassNameWithoutConstructor | core/ |
|
SomeAnnotationClassNameWithoutConstructorAndProperties | core/ |
|
SomeAnnotationWithConstructorWithoutParams | core/ |
|
Template | core/ |
|
Translation | core/ |
Defines a translatable annotation object. |
Version | core/ |
Plugin annotation @Target("PROPERTY"); |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.