Skip to content
Snippets Groups Projects
Verified Commit e32a8fd3 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3420987 by kim.pepper, smustgrave: Convert DataType plugin discovery to attributes

parent d17c8302
No related branches found
No related tags found
35 merge requests!12227Issue #3181946 by jonmcl, mglaman,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!6880Add @property to the DateTimeItem,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3478Issue #3337882: Deleted menus are not removed from content type config,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!213Issue #2906496: Give Media a menu item under Content
Pipeline #108849 canceled
Showing
with 214 additions and 107 deletions
......@@ -4,7 +4,10 @@
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver;
use Drupal\Core\Entity\TypedData\EntityDataDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\Exception\MissingDataException;
use Drupal\Core\TypedData\TypedData;
......@@ -17,15 +20,14 @@
*
* In addition to the "entity" data type, this exposes derived
* "entity:$entity_type" and "entity:$entity_type:$bundle" data types.
*
* @DataType(
* id = "entity",
* label = @Translation("Entity"),
* description = @Translation("All kind of entities, e.g. nodes, comments or users."),
* deriver = "\Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver",
* definition_class = "\Drupal\Core\Entity\TypedData\EntityDataDefinition"
* )
*/
#[DataType(
id: "entity",
label: new TranslatableMarkup("Entity"),
description: new TranslatableMarkup("All kind of entities, e.g. nodes, comments or users."),
definition_class: EntityDataDefinition::class,
deriver: EntityDeriver::class
)]
class EntityAdapter extends TypedData implements \IteratorAggregate, ComplexDataInterface {
/**
......
......@@ -3,7 +3,10 @@
namespace Drupal\Core\Entity\Plugin\DataType;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\DataReferenceBase;
use Drupal\Core\TypedData\DataReferenceDefinition;
/**
* Defines an 'entity_reference' data type.
......@@ -24,13 +27,12 @@
* \Drupal\Core\TypedData\DataReferenceDefinition::create('entity')
* ->setTargetDefinition($definition);
* @endcode
*
* @DataType(
* id = "entity_reference",
* label = @Translation("Entity reference"),
* definition_class = "\Drupal\Core\TypedData\DataReferenceDefinition"
* )
*/
#[DataType(
id: "entity_reference",
label: new TranslatableMarkup("Entity reference"),
definition_class: DataReferenceDefinition::class,
)]
class EntityReference extends DataReferenceBase {
/**
......
......@@ -2,19 +2,23 @@
namespace Drupal\Core\Field\Plugin\DataType;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Field\Plugin\DataType\Deriver\FieldItemDeriver;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
/**
* Defines the base plugin for deriving data types for field types.
*
* Note that the class only register the plugin, and is actually never used.
* \Drupal\Core\Field\FieldItemBase is available for use as base class.
*
* @DataType(
* id = "field_item",
* label = @Translation("Field item"),
* list_class = "\Drupal\Core\Field\FieldItemList",
* deriver = "Drupal\Core\Field\Plugin\DataType\Deriver\FieldItemDeriver"
* )
*/
#[DataType(
id: "field_item",
label: new TranslatableMarkup("Field item"),
list_class: FieldItemList::class,
deriver: FieldItemDeriver::class
)]
abstract class FieldItem {
}
<?php
declare(strict_types=1);
namespace Drupal\Core\TypedData\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\ListDataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
/**
* Defines a data type attribute.
*
* The typed data API allows modules to support any kind of data based upon
* pre-defined primitive types and interfaces for complex data and lists.
*
* Defined data types may map to one of the pre-defined primitive types below
* \Drupal\Core\TypedData\Type or may be complex data types, containing
* one or more data properties. Typed data objects for complex data types have
* to implement the \Drupal\Core\TypedData\ComplexDataInterface. Further
* interfaces that may be implemented are:
* - \Drupal\Core\Access\AccessibleInterface
* - \Drupal\Core\TypedData\TranslatableInterface
*
* Furthermore, lists of data items are represented by objects implementing the
* \Drupal\Core\TypedData\ListInterface. A list contains items of the same data
* type, is ordered and may contain duplicates. The class used for a list of
* items of a certain type may be specified using the 'list class' key.
*
* @see \Drupal::typedDataManager()
* @see \Drupal\Core\TypedData\TypedDataManager::create()
* @see hook_data_type_info_alter()
*
* @ingroup typed_data
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class DataType extends Plugin {
/**
* Constructs a new DataType attribute.
*
* @param string $id
* The data type plugin ID.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $label
* The human-readable name of the data type.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
* (optional) The description of the data type.
* @param string|null $definition_class
* (optional) The definition class to use for defining data of this type.
* @param string|null $list_class
* (optional) The typed data class used for wrapping multiple data items of
* the type.
* @param string|null $list_definition_class
* (optional) The definition class to use for defining a list of items of
* this type.
* @param array $constraints
* (optional) An array of validation constraints for this type.
* @param bool $unwrap_for_canonical_representation
* Whether the typed object wraps the canonical representation of the data.
* @param string|null $deriver
* (optional) The deriver class for the data type.
*
* @see \Drupal\Core\TypedData\TypedDataManager::getConstraints()
* @see \Drupal\Core\TypedData\TypedDataManager::getCanonicalRepresentation()
*/
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup $label,
public readonly ?TranslatableMarkup $description = NULL,
public readonly ?string $definition_class = DataDefinition::class,
public readonly ?string $list_class = ItemList::class,
public readonly ?string $list_definition_class = ListDataDefinition::class,
public readonly array $constraints = [],
public readonly bool $unwrap_for_canonical_representation = TRUE,
public readonly ?string $deriver = NULL,
) {}
}
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\TypedData;
/**
......@@ -10,12 +12,11 @@
* The "any" data type does not implement a list or complex data interface, nor
* is it mappable to any primitive type. Thus, it may contain any PHP data for
* which no further metadata is available.
*
* @DataType(
* id = "any",
* label = @Translation("Any data")
* )
*/
#[DataType(
id: "any",
label: new TranslatableMarkup("Any data")
)]
class Any extends TypedData {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\PrimitiveBase;
use Drupal\Core\TypedData\Type\BinaryInterface;
......@@ -11,12 +13,11 @@
* The plain value of binary data is a PHP file resource, see
* http://php.net/manual/language.types.resource.php. For setting the value
* a PHP file resource or an (absolute) stream resource URI may be passed.
*
* @DataType(
* id = "binary",
* label = @Translation("Binary")
* )
*/
#[DataType(
id: "binary",
label: new TranslatableMarkup("Binary")
)]
class BinaryData extends PrimitiveBase implements BinaryInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\PrimitiveBase;
use Drupal\Core\TypedData\Type\BooleanInterface;
......@@ -10,12 +12,11 @@
*
* The plain value of a boolean is a regular PHP boolean. For setting the value
* any PHP variable that casts to a boolean may be passed.
*
* @DataType(
* id = "boolean",
* label = @Translation("Boolean")
* )
*/
#[DataType(
id: "boolean",
label: new TranslatableMarkup("Boolean")
)]
class BooleanData extends PrimitiveBase implements BooleanInterface {
/**
......
......@@ -3,18 +3,19 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DateTimeInterface;
/**
* A data type for ISO 8601 date strings.
*
* The plain value of this data type is a date string in ISO 8601 format.
*
* @DataType(
* id = "datetime_iso8601",
* label = @Translation("Date")
* )
*/
#[DataType(
id: "datetime_iso8601",
label: new TranslatableMarkup("Date")
)]
class DateTimeIso8601 extends StringData implements DateTimeInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DecimalInterface;
/**
......@@ -10,12 +12,11 @@
* Decimal type is stored as "decimal" in the relational database. Because PHP
* does not have a primitive type decimal and using float can result in
* unexpected rounding behavior, it is implemented and displayed as string.
*
* @DataType(
* id = "decimal",
* label = @Translation("Decimal")
* )
*/
#[DataType(
id: "decimal",
label: new TranslatableMarkup("Decimal"),
)]
class DecimalData extends StringData implements DecimalInterface {
/**
......
......@@ -2,18 +2,19 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DurationInterface;
/**
* The duration ISO8601 data type.
*
* The plain value of this data type is an ISO8601 duration string.
*
* @DataType(
* id = "duration_iso8601",
* label = @Translation("Duration")
* )
*/
#[DataType(
id: "duration_iso8601",
label: new TranslatableMarkup("Duration")
)]
class DurationIso8601 extends StringData implements DurationInterface {
/**
......
......@@ -2,19 +2,20 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\StringInterface;
/**
* The Email data type.
*
* The plain value of Email is the email address represented as PHP string.
*
* @DataType(
* id = "email",
* label = @Translation("Email"),
* constraints = {"Email" = {}}
* )
*/
#[DataType(
id: "email",
label: new TranslatableMarkup("Email"),
constraints: ["Email" => []],
)]
class Email extends StringData implements StringInterface {
}
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\PrimitiveBase;
use Drupal\Core\TypedData\Type\FloatInterface;
......@@ -10,12 +12,11 @@
*
* The plain value of a float is a regular PHP float. For setting the value
* any PHP variable that casts to a float may be passed.
*
* @DataType(
* id = "float",
* label = @Translation("Float")
* )
*/
#[DataType(
id: "float",
label: new TranslatableMarkup("Float")
)]
class FloatData extends PrimitiveBase implements FloatInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\PrimitiveBase;
use Drupal\Core\TypedData\Type\IntegerInterface;
......@@ -10,12 +12,11 @@
*
* The plain value of an integer is a regular PHP integer. For setting the value
* any PHP variable that casts to an integer may be passed.
*
* @DataType(
* id = "integer",
* label = @Translation("Integer")
* )
*/
#[DataType(
id: "integer",
label: new TranslatableMarkup("Integer")
)]
class IntegerData extends PrimitiveBase implements IntegerInterface {
/**
......
......@@ -2,7 +2,10 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\ListDataDefinition;
use Drupal\Core\TypedData\ListInterface;
use Drupal\Core\TypedData\TypedData;
use Drupal\Core\TypedData\TypedDataInterface;
......@@ -16,13 +19,12 @@
* Note: The class cannot be called "List" as list is a reserved PHP keyword.
*
* @ingroup typed_data
*
* @DataType(
* id = "list",
* label = @Translation("List of items"),
* definition_class = "\Drupal\Core\TypedData\ListDataDefinition"
* )
*/
#[DataType(
id: "list",
label: new TranslatableMarkup("List of items"),
definition_class: ListDataDefinition::class,
)]
class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\TypedData;
/**
......@@ -10,13 +12,12 @@
* The plain value of a language is the language object, i.e. an instance of
* \Drupal\Core\Language\Language. For setting the value the language object or
* the language code as string may be passed.
*
* @DataType(
* id = "language",
* label = @Translation("Language"),
* description = @Translation("A language object.")
* )
*/
#[DataType(
id: "language",
label: new TranslatableMarkup("Language"),
description: new TranslatableMarkup("A language object.")
)]
class Language extends TypedData {
/**
......
......@@ -3,7 +3,10 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\DataReferenceBase;
use Drupal\Core\TypedData\DataReferenceDefinition;
/**
* Defines the 'language_reference' data type.
......@@ -14,13 +17,12 @@
* The plain value is the language object, i.e. an instance of
* \Drupal\Core\Language\Language. For setting the value the language object or
* the language code as string may be passed.
*
* @DataType(
* id = "language_reference",
* label = @Translation("Language reference"),
* definition_class = "\Drupal\Core\TypedData\DataReferenceDefinition"
* )
*/
#[DataType(
id: "language_reference",
label: new TranslatableMarkup("Language reference"),
definition_class: DataReferenceDefinition::class,
)]
class LanguageReference extends DataReferenceBase {
/**
......
......@@ -2,8 +2,11 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\TypedData\TypedData;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\MapDataDefinition;
use Drupal\Core\TypedData\TypedData;
/**
* The "map" data type.
......@@ -17,13 +20,12 @@
* it.
*
* @ingroup typed_data
*
* @DataType(
* id = "map",
* label = @Translation("Map"),
* definition_class = "\Drupal\Core\TypedData\MapDataDefinition"
* )
*/
#[DataType(
id: "map",
label: new TranslatableMarkup("Map"),
definition_class: MapDataDefinition::class,
)]
class Map extends TypedData implements \IteratorAggregate, ComplexDataInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\PrimitiveBase;
use Drupal\Core\TypedData\Type\StringInterface;
......@@ -10,12 +12,11 @@
*
* The plain value of a string is a regular PHP string. For setting the value
* any PHP variable that casts to a string may be passed.
*
* @DataType(
* id = "string",
* label = @Translation("String")
* )
*/
#[DataType(
id: "string",
label: new TranslatableMarkup("String")
)]
class StringData extends PrimitiveBase implements StringInterface {
/**
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DurationInterface;
/**
......@@ -13,13 +15,12 @@
* hours due to daylight savings). If that's an issue, consider using
* \Drupal\Core\TypedData\Type\DurationIso8601 instead.
*
* @DataType(
* id = "timespan",
* label = @Translation("Time span in seconds")
* )
*
* @see \Drupal\Core\TypedData\Type\DurationIso8601
*/
#[DataType(
id: "timespan",
label: new TranslatableMarkup("Time span in seconds"),
)]
class TimeSpan extends IntegerData implements DurationInterface {
/**
......
......@@ -3,16 +3,17 @@
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DateTimeInterface;
/**
* The timestamp data type.
*
* @DataType(
* id = "timestamp",
* label = @Translation("Timestamp")
* )
*/
#[DataType(
id: "timestamp",
label: new TranslatableMarkup("Timestamp"),
)]
class Timestamp extends IntegerData implements DateTimeInterface {
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment