1. 8.5.x core/core.api.php annotation
  2. 8.0.x core/core.api.php annotation
  3. 8.1.x core/core.api.php annotation
  4. 8.2.x core/core.api.php annotation
  5. 8.3.x core/core.api.php annotation
  6. 8.4.x core/core.api.php annotation
  7. 8.6.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


core/core.api.php, line 1871
Documentation landing page and topics, plus core library hooks.


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


liquidcms’s picture

Is there full annotation documentation somewhere?

In particular, I have a @ContentEntityType annotation for a custom entity type and it has a CRUD "links" section. I have added {var1} wildcards to the links and this works; but how do I make these path wildcards optional? I would expect I do it by setting wildcard defaults as I do in a routing file; but I can't figure out the format.