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 1824
- Documentation landing page and topics, plus core library hooks.
Classes
Name | Location | Description |
---|---|---|
Action | core/lib/Drupal/Core/Annotation/Action.php | Defines an Action annotation object. |
AggregatorFetcher | core/modules/aggregator/src/Annotation/AggregatorFetcher.php | Defines a Plugin annotation object for aggregator fetcher plugins. |
AggregatorParser | core/modules/aggregator/src/Annotation/AggregatorParser.php | Defines a Plugin annotation object for aggregator parser plugins. |
AggregatorProcessor | core/modules/aggregator/src/Annotation/AggregatorProcessor.php | Defines a Plugin annotation object for aggregator processor plugins. |
Archiver | core/lib/Drupal/Core/Archiver/Annotation/Archiver.php | Defines an archiver annotation object. |
Block | core/lib/Drupal/Core/Block/Annotation/Block.php | Defines a Block annotation object. |
CKEditorPlugin | core/modules/ckeditor/src/Annotation/CKEditorPlugin.php | Defines a CKEditorPlugin annotation object. |
Condition | core/lib/Drupal/Core/Condition/Annotation/Condition.php | Defines a condition plugin annotation object. |
ConfigEntityType | core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php | Defines a config entity type annotation object. |
Constraint | core/lib/Drupal/Core/Validation/Annotation/Constraint.php | Defines a validation constraint annotation object. |
ContentEntityType | core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php | Defines a content entity type annotation object. |
ContextDefinition | core/lib/Drupal/Core/Annotation/ContextDefinition.php | Defines a context definition annotation object. |
DataType | core/lib/Drupal/Core/TypedData/Annotation/DataType.php | Defines a data type annotation object. |
DisplayVariant | core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php | Defines a display variant annotation object. |
Editor | core/modules/editor/src/Annotation/Editor.php | Defines an Editor annotation object. |
EntityReferenceSelection | core/lib/Drupal/Core/Entity/Annotation/EntityReferenceSelection.php | Defines an EntityReferenceSelection plugin annotation object. |
EntityType | core/lib/Drupal/Core/Entity/Annotation/EntityType.php | Defines an Entity type annotation object. |
FieldFormatter | core/lib/Drupal/Core/Field/Annotation/FieldFormatter.php | Defines a FieldFormatter annotation object. |
FieldType | core/lib/Drupal/Core/Field/Annotation/FieldType.php | Defines a FieldType annotation object. |
FieldWidget | core/lib/Drupal/Core/Field/Annotation/FieldWidget.php | Defines a FieldWidget annotation object. |
Filter | core/modules/filter/src/Annotation/Filter.php | Defines an filter annotation object. |
FormElement | core/lib/Drupal/Core/Render/Annotation/FormElement.php | Defines a form element plugin annotation object. |
HelpSection | core/modules/help/src/Annotation/HelpSection.php | Defines a Plugin annotation object for help page section plugins. |
ImageEffect | core/modules/image/src/Annotation/ImageEffect.php | Defines an image effect annotation object. |
ImageToolkit | core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkit.php | Defines a Plugin annotation object for the image toolkit plugin. |
ImageToolkitOperation | core/lib/Drupal/Core/ImageToolkit/Annotation/ImageToolkitOperation.php | Defines a Plugin annotation object for the image toolkit operation plugin. |
InPlaceEditor | core/modules/quickedit/src/Annotation/InPlaceEditor.php | Defines an InPlaceEditor annotation object. |
LanguageNegotiation | core/modules/language/src/Annotation/LanguageNegotiation.php | Defines a language negotiation annotation object. |
core/lib/Drupal/Core/Annotation/Mail.php | Defines a Mail annotation object. | |
MigrateCckField | core/modules/migrate_drupal/src/Annotation/MigrateCckField.php | Defines a cckfield plugin annotation object. |
MigrateDestination | core/modules/migrate/src/Annotation/MigrateDestination.php | Defines a migration destination plugin annotation object. |
MigrateProcessPlugin | core/modules/migrate/src/Annotation/MigrateProcessPlugin.php | Defines a migration process plugin annotation object. |
MigrateSource | core/modules/migrate/src/Annotation/MigrateSource.php | Defines a migration source plugin annotation object. |
PageDisplayVariant | core/lib/Drupal/Core/Display/Annotation/PageDisplayVariant.php | Defines a page display variant annotation object. |
Plugin | core/lib/Drupal/Component/Annotation/Plugin.php | Defines a Plugin annotation object. |
PluginExample | core/modules/system/tests/modules/plugin_test/src/Plugin/Annotation/PluginExample.php | Defines a custom Plugin annotation. |
PluginExtended | core/modules/system/tests/modules/plugin_test_extended/src/Plugin/Annotation/PluginExtended.php | Defines a test annotation that extends an annotation in another namespace. |
PluginID | core/lib/Drupal/Component/Annotation/PluginID.php | Defines a Plugin annotation object that just contains an ID. |
PluralTranslation | core/lib/Drupal/Core/Annotation/PluralTranslation.php | Defines an annotation object for strings that require plural forms. |
QueueWorker | core/lib/Drupal/Core/Annotation/QueueWorker.php | Declare a worker class for processing a queue item. |
RenderElement | core/lib/Drupal/Core/Render/Annotation/RenderElement.php | Defines a render element plugin annotation object. |
RestResource | core/modules/rest/src/Annotation/RestResource.php | Defines a REST resource annotation object. |
SearchPlugin | core/modules/search/src/Annotation/SearchPlugin.php | Defines a SearchPlugin type annotation object. |
Tip | core/modules/tour/src/Annotation/Tip.php | Defines a tour item annotation object. |
Translation | core/lib/Drupal/Core/Annotation/Translation.php | Defines a translatable annotation object. |
ViewsAccess | core/modules/views/src/Annotation/ViewsAccess.php | Defines a Plugin annotation object for views access plugins. |
ViewsArea | core/modules/views/src/Annotation/ViewsArea.php | Defines a Plugin annotation object for views area handlers. |
ViewsArgument | core/modules/views/src/Annotation/ViewsArgument.php | Defines a Plugin annotation object for views argument handlers. |
ViewsArgumentDefault | core/modules/views/src/Annotation/ViewsArgumentDefault.php | Defines a Plugin annotation object for views argument default plugins. |
ViewsArgumentValidator | core/modules/views/src/Annotation/ViewsArgumentValidator.php | Defines a Plugin annotation object for views argument validator plugins. |
ViewsCache | core/modules/views/src/Annotation/ViewsCache.php | Defines a Plugin annotation object for views cache plugins. |
ViewsDisplay | core/modules/views/src/Annotation/ViewsDisplay.php | Defines a Plugin annotation object for views display plugins. |
ViewsDisplayExtender | core/modules/views/src/Annotation/ViewsDisplayExtender.php | Defines a Plugin annotation object for views display extender plugins. |
ViewsExposedForm | core/modules/views/src/Annotation/ViewsExposedForm.php | Defines a Plugin annotation object for views exposed form plugins. |
ViewsField | core/modules/views/src/Annotation/ViewsField.php | Defines a Plugin annotation object for views field handlers. |
ViewsFilter | core/modules/views/src/Annotation/ViewsFilter.php | Defines a Plugin annotation object for views filter handlers. |
ViewsJoin | core/modules/views/src/Annotation/ViewsJoin.php | Defines a Plugin annotation object for views join plugins. |
ViewsPager | core/modules/views/src/Annotation/ViewsPager.php | Defines a Plugin annotation object for views pager plugins. |
ViewsQuery | core/modules/views/src/Annotation/ViewsQuery.php | Defines a Plugin annotation object for views query plugins. |
ViewsRelationship | core/modules/views/src/Annotation/ViewsRelationship.php | Defines a Plugin annotation object for views relationship handlers. |
ViewsRow | core/modules/views/src/Annotation/ViewsRow.php | Defines a Plugin annotation object for views row plugins. |
ViewsSort | core/modules/views/src/Annotation/ViewsSort.php | Defines a Plugin annotation object for views sort handlers. |
ViewsStyle | core/modules/views/src/Annotation/ViewsStyle.php | Defines a Plugin annotation object for views style plugins. |
ViewsWizard | core/modules/views/src/Annotation/ViewsWizard.php | Defines a Plugin annotation object for views wizard plugins. |
Please login to continue.