You are here

Annotations in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 1741
Documentation landing page and topics, plus core library hooks.

Classes

Namesort descending 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.
All vendor/symfony/validator/Constraints/All.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Archiver core/lib/Drupal/Core/Archiver/Annotation/Archiver.php Defines an archiver annotation object.
Attribute vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php Annotation that can be used to signal to the parser to check the attribute type during the parsing process.
Attributes vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php Annotation that can be used to signal to the parser to check the types of all declared attributes during the parsing process.
Blank vendor/symfony/validator/Constraints/Blank.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Block core/lib/Drupal/Core/Block/Annotation/Block.php Defines a Block annotation object.
Callback vendor/symfony/validator/Constraints/Callback.php @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
CardScheme vendor/symfony/validator/Constraints/CardScheme.php Metadata for the CardSchemeValidator.
Choice vendor/symfony/validator/Constraints/Choice.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
CKEditorPlugin core/modules/ckeditor/src/Annotation/CKEditorPlugin.php Defines a CKEditorPlugin annotation object.
Collection vendor/symfony/validator/Constraints/Collection.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
ConstraintA vendor/symfony/validator/Tests/Fixtures/ConstraintA.php
ConstraintB vendor/symfony/validator/Tests/Fixtures/ConstraintB.php
ConstraintC vendor/symfony/validator/Tests/Fixtures/ConstraintC.php
ConstraintWithValue vendor/symfony/validator/Tests/Fixtures/ConstraintWithValue.php
ConstraintWithValueAsDefault vendor/symfony/validator/Tests/Fixtures/ConstraintWithValueAsDefault.php
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.
Count vendor/symfony/validator/Constraints/Count.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Country vendor/symfony/validator/Constraints/Country.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Currency vendor/symfony/validator/Constraints/Currency.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
DataType core/lib/Drupal/Core/TypedData/Annotation/DataType.php Defines a data type annotation object.
Date vendor/symfony/validator/Constraints/Date.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
DateTime vendor/symfony/validator/Constraints/DateTime.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
Email vendor/symfony/validator/Constraints/Email.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Entity vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/annotation/TestClass.php
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.
Enum vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php Annotation that can be used to signal to the parser to check the available values during the parsing process.
EqualTo vendor/symfony/validator/Constraints/EqualTo.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Expression vendor/symfony/validator/Constraints/Expression.php @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
False Deprecated vendor/symfony/validator/Constraints/False.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
File vendor/symfony/validator/Constraints/File.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
GreaterThan vendor/symfony/validator/Constraints/GreaterThan.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
GreaterThanOrEqual vendor/symfony/validator/Constraints/GreaterThanOrEqual.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Groups vendor/symfony/serializer/Annotation/Groups.php Annotation class for @Groups().
GroupSequence Deprecated vendor/symfony/validator/Constraints/GroupSequence.php A sequence of validation groups.
GroupSequenceProvider vendor/symfony/validator/Constraints/GroupSequenceProvider.php Annotation to define a group sequence provider.
Iban vendor/symfony/validator/Constraints/Iban.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
IdenticalTo vendor/symfony/validator/Constraints/IdenticalTo.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
IgnoreAnnotation vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php Annotation that can be used to signal to the parser to ignore specific annotations during the parsing process.
Image vendor/symfony/validator/Constraints/Image.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
Ip vendor/symfony/validator/Constraints/Ip.php Validates that a value is a valid IP address.
Isbn vendor/symfony/validator/Constraints/Isbn.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
IsFalse vendor/symfony/validator/Constraints/IsFalse.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
IsNull vendor/symfony/validator/Constraints/IsNull.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Issn vendor/symfony/validator/Constraints/Issn.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
IsTrue vendor/symfony/validator/Constraints/IsTrue.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Language vendor/symfony/validator/Constraints/Language.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
LanguageNegotiation core/modules/language/src/Annotation/LanguageNegotiation.php Defines a language negotiation annotation object.
Length vendor/symfony/validator/Constraints/Length.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
LessThan vendor/symfony/validator/Constraints/LessThan.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
LessThanOrEqual vendor/symfony/validator/Constraints/LessThanOrEqual.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Locale vendor/symfony/validator/Constraints/Locale.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Luhn vendor/symfony/validator/Constraints/Luhn.php Metadata for the LuhnValidator.
Mail 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.
NotBlank vendor/symfony/validator/Constraints/NotBlank.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
NotEqualTo vendor/symfony/validator/Constraints/NotEqualTo.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
NotIdenticalTo vendor/symfony/validator/Constraints/NotIdenticalTo.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
NotNull vendor/symfony/validator/Constraints/NotNull.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Null Deprecated vendor/symfony/validator/Constraints/Null.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Optional vendor/symfony/validator/Constraints/Optional.php @Target({"ANNOTATION"})
Optional Deprecated vendor/symfony/validator/Constraints/Collection/Optional.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
PluginID core/lib/Drupal/Component/Annotation/PluginID.php Defines a Plugin annotation object that just contains an ID.
QueueWorker core/lib/Drupal/Core/Annotation/QueueWorker.php Declare queue workers that need to be run periodically.
Range vendor/symfony/validator/Constraints/Range.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Regex vendor/symfony/validator/Constraints/Regex.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
RenderElement core/lib/Drupal/Core/Render/Annotation/RenderElement.php Defines a render element plugin annotation object.
Required vendor/symfony/validator/Constraints/Required.php @Target({"ANNOTATION"})
Required Deprecated vendor/symfony/validator/Constraints/Collection/Required.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Required vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.php Annotation that can be used to signal to the parser to check if that attribute is required during the parsing process.
RestResource core/modules/rest/src/Annotation/RestResource.php Defines a REST resource annotation object.
Route vendor/symfony/routing/Annotation/Route.php Annotation class for @Route().
SearchPlugin core/modules/search/src/Annotation/SearchPlugin.php Defines a SearchPlugin type annotation object.
Target vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php Annotation that can be used to signal to the parser to check the annotation target during the parsing process.
Time vendor/symfony/validator/Constraints/Time.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.
Traverse vendor/symfony/validator/Constraints/Traverse.php @since 2.5
True Deprecated vendor/symfony/validator/Constraints/True.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Type vendor/symfony/validator/Constraints/Type.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Url vendor/symfony/validator/Constraints/Url.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Uuid vendor/symfony/validator/Constraints/Uuid.php @author Colin O'Dell <colinodell@gmail.com> @author Bernhard Schussek <bschussek@gmail.com>
Valid vendor/symfony/validator/Constraints/Valid.php @Target({"PROPERTY", "METHOD", "ANNOTATION"})
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.