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

Issue #3420978 by mstrelan, smustgrave: Convert FieldWidget plugin discovery to attributes

(cherry picked from commit d0e96114)
parent cd8d76a2
No related branches found
No related tags found
27 merge requests!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #108872 passed with warnings
Pipeline: drupal

#108882

    Pipeline: drupal

    #108874

      Showing
      with 208 additions and 161 deletions
      ......@@ -3,22 +3,23 @@
      namespace Drupal\Core\Datetime\Plugin\Field\FieldWidget;
      use Drupal\Core\Datetime\DrupalDateTime;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'datetime timestamp' widget.
      *
      * @FieldWidget(
      * id = "datetime_timestamp",
      * label = @Translation("Datetime Timestamp"),
      * field_types = {
      * "timestamp",
      * "created",
      * }
      * )
      */
      #[FieldWidget(
      id: 'datetime_timestamp',
      label: new TranslatableMarkup('Datetime Timestamp'),
      field_types: [
      'timestamp',
      'created',
      ],
      )]
      class TimestampDatetimeWidget extends WidgetBase {
      /**
      ......
      <?php
      namespace Drupal\Core\Field\Attribute;
      use Drupal\Component\Plugin\Attribute\Plugin;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Defines a FieldWidget attribute for plugin discovery.
      *
      * Plugin Namespace: Plugin\Field\FieldWidget
      *
      * Widgets handle how fields are displayed in edit forms.
      *
      * Additional attribute keys for widgets can be defined in
      * hook_field_widget_info_alter().
      *
      * @see \Drupal\Core\Field\WidgetPluginManager
      * @see \Drupal\Core\Field\WidgetInterface
      *
      * @ingroup field_widget
      */
      #[\Attribute(\Attribute::TARGET_CLASS)]
      class FieldWidget extends Plugin {
      /**
      * Constructs a FieldWidget attribute.
      *
      * @param string $id
      * The plugin ID.
      * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
      * (optional) The human-readable name of the widget type.
      * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
      * (optional) A short description of the widget type.
      * @param string[] $field_types
      * (optional) An array of field types the widget supports.
      * @param bool $multiple_values
      * (optional) Does the field widget handles multiple values at once.
      * @param int|null $weight
      * (optional) An integer to determine weight of this widget relative to
      * other widgets. Other widgets are in the Field UI when selecting a widget
      * for a given field.
      * @param class-string|null $deriver
      * (optional) The deriver class.
      */
      public function __construct(
      public readonly string $id,
      public readonly ?TranslatableMarkup $label = NULL,
      public readonly ?TranslatableMarkup $description = NULL,
      public readonly array $field_types = [],
      public readonly bool $multiple_values = FALSE,
      public readonly ?int $weight = NULL,
      public readonly ?string $deriver = NULL,
      ) {}
      }
      ......@@ -2,22 +2,21 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'boolean_checkbox' widget.
      *
      * @FieldWidget(
      * id = "boolean_checkbox",
      * label = @Translation("Single on/off checkbox"),
      * field_types = {
      * "boolean"
      * },
      * multiple_values = TRUE
      * )
      */
      #[FieldWidget(
      id: 'boolean_checkbox',
      label: new TranslatableMarkup('Single on/off checkbox'),
      field_types: ['boolean'],
      multiple_values: TRUE,
      )]
      class BooleanCheckboxWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,22 +2,21 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\Render\Element\Email;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'email_default' widget.
      *
      * @FieldWidget(
      * id = "email_default",
      * label = @Translation("Email"),
      * field_types = {
      * "email"
      * }
      * )
      */
      #[FieldWidget(
      id: 'email_default',
      label: new TranslatableMarkup('Email'),
      field_types: ['email'],
      )]
      class EmailDefaultWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,22 +2,21 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'entity_reference_autocomplete_tags' widget.
      *
      * @FieldWidget(
      * id = "entity_reference_autocomplete_tags",
      * label = @Translation("Autocomplete (Tags style)"),
      * description = @Translation("An autocomplete text field with tagging support."),
      * field_types = {
      * "entity_reference"
      * },
      * multiple_values = TRUE
      * )
      */
      #[FieldWidget(
      id: 'entity_reference_autocomplete_tags',
      label: new TranslatableMarkup('Autocomplete (Tags style)'),
      description: new TranslatableMarkup('An autocomplete text field with tagging support.'),
      field_types: ['entity_reference'],
      multiple_values: TRUE,
      )]
      class EntityReferenceAutocompleteTagsWidget extends EntityReferenceAutocompleteWidget {
      /**
      ......
      ......@@ -2,24 +2,23 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Drupal\user\EntityOwnerInterface;
      use Symfony\Component\Validator\ConstraintViolationInterface;
      /**
      * Plugin implementation of the 'entity_reference_autocomplete' widget.
      *
      * @FieldWidget(
      * id = "entity_reference_autocomplete",
      * label = @Translation("Autocomplete"),
      * description = @Translation("An autocomplete text field."),
      * field_types = {
      * "entity_reference"
      * }
      * )
      */
      #[FieldWidget(
      id: 'entity_reference_autocomplete',
      label: new TranslatableMarkup('Autocomplete'),
      description: new TranslatableMarkup('An autocomplete text field.'),
      field_types: ['entity_reference'],
      )]
      class EntityReferenceAutocompleteWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,22 +2,21 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\Language\LanguageInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'Language' widget.
      *
      * @FieldWidget(
      * id = "language_select",
      * label = @Translation("Language select"),
      * field_types = {
      * "language"
      * }
      * )
      */
      #[FieldWidget(
      id: 'language_select',
      label: new TranslatableMarkup('Language select'),
      field_types: ['language'],
      )]
      class LanguageSelectWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,25 +2,26 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldFilteredMarkup;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Symfony\Component\Validator\ConstraintViolationInterface;
      /**
      * Plugin implementation of the 'number' widget.
      *
      * @FieldWidget(
      * id = "number",
      * label = @Translation("Number field"),
      * field_types = {
      * "integer",
      * "decimal",
      * "float"
      * }
      * )
      */
      #[FieldWidget(
      id: 'number',
      label: new TranslatableMarkup('Number field'),
      field_types: [
      'integer',
      'decimal',
      'float',
      ],
      )]
      class NumberWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,25 +2,26 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'options_buttons' widget.
      *
      * @FieldWidget(
      * id = "options_buttons",
      * label = @Translation("Check boxes/radio buttons"),
      * field_types = {
      * "boolean",
      * "entity_reference",
      * "list_integer",
      * "list_float",
      * "list_string",
      * },
      * multiple_values = TRUE
      * )
      */
      #[FieldWidget(
      id: 'options_buttons',
      label: new TranslatableMarkup('Check boxes/radio buttons'),
      field_types: [
      'boolean',
      'entity_reference',
      'list_integer',
      'list_float',
      'list_string',
      ],
      multiple_values: TRUE,
      )]
      class OptionsButtonsWidget extends OptionsWidgetBase {
      /**
      ......
      ......@@ -3,24 +3,25 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Component\Utility\Html;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'options_select' widget.
      *
      * @FieldWidget(
      * id = "options_select",
      * label = @Translation("Select list"),
      * field_types = {
      * "entity_reference",
      * "list_integer",
      * "list_float",
      * "list_string"
      * },
      * multiple_values = TRUE
      * )
      */
      #[FieldWidget(
      id: 'options_select',
      label: new TranslatableMarkup('Select list'),
      field_types: [
      'entity_reference',
      'list_integer',
      'list_float',
      'list_string',
      ],
      multiple_values: TRUE,
      )]
      class OptionsSelectWidget extends OptionsWidgetBase {
      /**
      ......
      ......@@ -2,21 +2,20 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'string_textarea' widget.
      *
      * @FieldWidget(
      * id = "string_textarea",
      * label = @Translation("Text area (multiple rows)"),
      * field_types = {
      * "string_long"
      * }
      * )
      */
      #[FieldWidget(
      id: 'string_textarea',
      label: new TranslatableMarkup('Text area (multiple rows)'),
      field_types: ['string_long'],
      )]
      class StringTextareaWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,21 +2,20 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'string_textfield' widget.
      *
      * @FieldWidget(
      * id = "string_textfield",
      * label = @Translation("Textfield"),
      * field_types = {
      * "string"
      * }
      * )
      */
      #[FieldWidget(
      id: 'string_textfield',
      label: new TranslatableMarkup('Textfield'),
      field_types: ['string'],
      )]
      class StringTextfieldWidget extends WidgetBase {
      /**
      ......
      ......@@ -2,21 +2,20 @@
      namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'uri' widget.
      *
      * @FieldWidget(
      * id = "uri",
      * label = @Translation("URI field"),
      * field_types = {
      * "uri",
      * }
      * )
      */
      #[FieldWidget(
      id: 'uri',
      label: new TranslatableMarkup('URI field'),
      field_types: ['uri'],
      )]
      class UriWidget extends WidgetBase {
      /**
      ......
      ......@@ -5,6 +5,7 @@
      use Drupal\Component\Plugin\Factory\DefaultFactory;
      use Drupal\Core\Cache\CacheBackendInterface;
      use Drupal\Core\Extension\ModuleHandlerInterface;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Plugin\DefaultPluginManager;
      /**
      ......@@ -42,7 +43,7 @@ class WidgetPluginManager extends DefaultPluginManager {
      * The 'field type' plugin manager.
      */
      public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager) {
      parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\WidgetInterface', 'Drupal\Core\Field\Annotation\FieldWidget');
      parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\WidgetInterface', FieldWidget::class, 'Drupal\Core\Field\Annotation\FieldWidget');
      $this->setCacheBackend($cache_backend, 'field_widget_types_plugins');
      $this->alterInfo('field_widget_info');
      ......
      ......@@ -4,21 +4,20 @@
      use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
      use Drupal\Component\Utility\Html;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\WidgetBase;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Provides a default comment widget.
      *
      * @FieldWidget(
      * id = "comment_default",
      * label = @Translation("Comment"),
      * field_types = {
      * "comment"
      * }
      * )
      */
      #[FieldWidget(
      id: 'comment_default',
      label: new TranslatableMarkup('Comment'),
      field_types: ['comment'],
      )]
      class CommentWidget extends WidgetBase {
      /**
      ......
      ......@@ -4,6 +4,7 @@
      use Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList;
      use Drupal\Core\Entity\EntityTypeManagerInterface;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldDefinitionInterface;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget;
      ......@@ -11,19 +12,17 @@
      use Drupal\Core\Session\AccountInterface;
      use Drupal\content_moderation\ModerationInformation;
      use Drupal\content_moderation\StateTransitionValidationInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Symfony\Component\DependencyInjection\ContainerInterface;
      /**
      * Plugin implementation of the 'moderation_state_default' widget.
      *
      * @FieldWidget(
      * id = "moderation_state_default",
      * label = @Translation("Moderation state"),
      * field_types = {
      * "string"
      * }
      * )
      */
      #[FieldWidget(
      id: 'moderation_state_default',
      label: new TranslatableMarkup('Moderation state'),
      field_types: ['string'],
      )]
      class ModerationStateWidget extends OptionsSelectWidget {
      /**
      ......
      ......@@ -2,20 +2,19 @@
      namespace Drupal\datetime\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      /**
      * Plugin implementation of the 'datetime_datelist' widget.
      *
      * @FieldWidget(
      * id = "datetime_datelist",
      * label = @Translation("Select list"),
      * field_types = {
      * "datetime"
      * }
      * )
      */
      #[FieldWidget(
      id: 'datetime_datelist',
      label: new TranslatableMarkup('Select list'),
      field_types: ['datetime'],
      )]
      class DateTimeDatelistWidget extends DateTimeWidgetBase {
      /**
      ......
      ......@@ -3,23 +3,22 @@
      namespace Drupal\datetime\Plugin\Field\FieldWidget;
      use Drupal\Core\Entity\EntityStorageInterface;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Field\FieldDefinitionInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
      use Symfony\Component\DependencyInjection\ContainerInterface;
      /**
      * Plugin implementation of the 'datetime_default' widget.
      *
      * @FieldWidget(
      * id = "datetime_default",
      * label = @Translation("Date and time"),
      * field_types = {
      * "datetime"
      * }
      * )
      */
      #[FieldWidget(
      id: 'datetime_default',
      label: new TranslatableMarkup('Date and time'),
      field_types: ['datetime'],
      )]
      class DateTimeDefaultWidget extends DateTimeWidgetBase {
      /**
      ......
      ......@@ -2,21 +2,20 @@
      namespace Drupal\datetime_range\Plugin\Field\FieldWidget;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
      /**
      * Plugin implementation of the 'daterange_datelist' widget.
      *
      * @FieldWidget(
      * id = "daterange_datelist",
      * label = @Translation("Select list"),
      * field_types = {
      * "daterange"
      * }
      * )
      */
      #[FieldWidget(
      id: 'daterange_datelist',
      label: new TranslatableMarkup('Select list'),
      field_types: ['daterange'],
      )]
      class DateRangeDatelistWidget extends DateRangeWidgetBase {
      /**
      ......
      ......@@ -3,23 +3,22 @@
      namespace Drupal\datetime_range\Plugin\Field\FieldWidget;
      use Drupal\Core\Entity\EntityStorageInterface;
      use Drupal\Core\Field\Attribute\FieldWidget;
      use Drupal\Core\Field\FieldDefinitionInterface;
      use Drupal\Core\Field\FieldItemListInterface;
      use Drupal\Core\Form\FormStateInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
      use Symfony\Component\DependencyInjection\ContainerInterface;
      /**
      * Plugin implementation of the 'daterange_default' widget.
      *
      * @FieldWidget(
      * id = "daterange_default",
      * label = @Translation("Date and time range"),
      * field_types = {
      * "daterange"
      * }
      * )
      */
      #[FieldWidget(
      id: 'daterange_default',
      label: new TranslatableMarkup('Date and time range'),
      field_types: ['daterange'],
      )]
      class DateRangeDefaultWidget extends DateRangeWidgetBase {
      /**
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment