From 77ccadfb8006374ca3208db31d7c8bffb3037d26 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 20 Mar 2024 08:01:46 +0000
Subject: [PATCH] Issue #3426961 by sorlov, Ruturaj Chaubey, mstrelan,
 smustgrave: Convert ViewsSort plugin discovery to attributes

---
 .../views/sort/StatisticsLastCommentName.php    |  4 ++--
 .../Plugin/views/sort/StatisticsLastUpdated.php |  4 ++--
 .../comment/src/Plugin/views/sort/Thread.php    |  4 ++--
 .../Plugin/views/sort/ModerationStateSort.php   |  4 ++--
 .../datetime/src/Plugin/views/sort/Date.php     |  4 ++--
 .../search/src/Plugin/views/sort/Score.php      |  4 ++--
 core/modules/views/src/Attribute/ViewsSort.php  | 17 +++++++++++++++++
 .../views/src/Plugin/views/sort/Broken.php      |  4 ++--
 .../views/src/Plugin/views/sort/Date.php        |  4 ++--
 .../src/Plugin/views/sort/GroupByNumeric.php    |  4 ++--
 .../views/src/Plugin/views/sort/Random.php      |  4 ++--
 .../src/Plugin/views/sort/SortPluginBase.php    |  4 ++--
 .../views/src/Plugin/views/sort/Standard.php    |  5 +++--
 13 files changed, 42 insertions(+), 24 deletions(-)
 create mode 100644 core/modules/views/src/Attribute/ViewsSort.php

diff --git a/core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php b/core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php
index ea6a5c356d7b..08d765d223c0 100644
--- a/core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php
+++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\comment\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\sort\SortPluginBase;
 
 /**
  * Sort handler, sorts by last comment name which can be in 2 different fields.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("comment_ces_last_comment_name")
  */
+#[ViewsSort("comment_ces_last_comment_name")]
 class StatisticsLastCommentName extends SortPluginBase {
 
   /**
diff --git a/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
index 076cc0c744da..adcf6b544661 100644
--- a/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
+++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\comment\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\sort\Date;
 
 /**
  * Sort handler for the newer of last comment / entity updated.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("comment_ces_last_updated")
  */
+#[ViewsSort("comment_ces_last_updated")]
 class StatisticsLastUpdated extends Date {
 
   /**
diff --git a/core/modules/comment/src/Plugin/views/sort/Thread.php b/core/modules/comment/src/Plugin/views/sort/Thread.php
index 353d79911094..63b2f6be26d8 100644
--- a/core/modules/comment/src/Plugin/views/sort/Thread.php
+++ b/core/modules/comment/src/Plugin/views/sort/Thread.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\comment\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\sort\SortPluginBase;
 
 /**
  * Sort handler for ordering by thread.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("comment_thread")
  */
+#[ViewsSort("comment_thread")]
 class Thread extends SortPluginBase {
 
   public function query() {
diff --git a/core/modules/content_moderation/src/Plugin/views/sort/ModerationStateSort.php b/core/modules/content_moderation/src/Plugin/views/sort/ModerationStateSort.php
index 813d063ae34f..26e2962e4bb8 100644
--- a/core/modules/content_moderation/src/Plugin/views/sort/ModerationStateSort.php
+++ b/core/modules/content_moderation/src/Plugin/views/sort/ModerationStateSort.php
@@ -4,6 +4,7 @@
 
 use Drupal\content_moderation\Plugin\views\ModerationStateJoinViewsHandlerTrait;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\sort\SortPluginBase;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
@@ -11,9 +12,8 @@
  * Enables sorting for the computed moderation_state field.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("moderation_state_sort")
  */
+#[ViewsSort("moderation_state_sort")]
 class ModerationStateSort extends SortPluginBase {
 
   use ModerationStateJoinViewsHandlerTrait;
diff --git a/core/modules/datetime/src/Plugin/views/sort/Date.php b/core/modules/datetime/src/Plugin/views/sort/Date.php
index 0049e867feb7..c00c3a427b60 100644
--- a/core/modules/datetime/src/Plugin/views/sort/Date.php
+++ b/core/modules/datetime/src/Plugin/views/sort/Date.php
@@ -3,6 +3,7 @@
 namespace Drupal\datetime\Plugin\views\sort;
 
 use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\FieldAPIHandlerTrait;
 use Drupal\views\Plugin\views\sort\Date as NumericDate;
 
@@ -11,9 +12,8 @@
  *
  * This handler enables granularity, which is the ability to make dates
  * equivalent based upon nearness.
- *
- * @ViewsSort("datetime")
  */
+#[ViewsSort("datetime")]
 class Date extends NumericDate {
 
   use FieldAPIHandlerTrait;
diff --git a/core/modules/search/src/Plugin/views/sort/Score.php b/core/modules/search/src/Plugin/views/sort/Score.php
index f5910f0d56ec..494312957cd0 100644
--- a/core/modules/search/src/Plugin/views/sort/Score.php
+++ b/core/modules/search/src/Plugin/views/sort/Score.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\search\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\sort\SortPluginBase;
 
 /**
  * Sort handler for sorting by search score.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("search_score")
  */
+#[ViewsSort("search_score")]
 class Score extends SortPluginBase {
 
   /**
diff --git a/core/modules/views/src/Attribute/ViewsSort.php b/core/modules/views/src/Attribute/ViewsSort.php
new file mode 100644
index 000000000000..58c9c9cb0296
--- /dev/null
+++ b/core/modules/views/src/Attribute/ViewsSort.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Drupal\views\Attribute;
+
+use Drupal\Component\Plugin\Attribute\PluginID;
+
+/**
+ * Defines a Plugin attribute object for views sort handlers.
+ *
+ * @see \Drupal\views\Plugin\views\sort\SortPluginBase
+ *
+ * @ingroup views_sort_handlers
+ */
+#[\Attribute(\Attribute::TARGET_CLASS)]
+class ViewsSort extends PluginID {
+
+}
diff --git a/core/modules/views/src/Plugin/views/sort/Broken.php b/core/modules/views/src/Plugin/views/sort/Broken.php
index 0a3a737d4bed..f2b56133a571 100644
--- a/core/modules/views/src/Plugin/views/sort/Broken.php
+++ b/core/modules/views/src/Plugin/views/sort/Broken.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\views\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\BrokenHandlerTrait;
 
 /**
  * A special handler to take the place of missing or broken handlers.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("broken")
  */
+#[ViewsSort("broken")]
 class Broken extends SortPluginBase {
   use BrokenHandlerTrait;
 
diff --git a/core/modules/views/src/Plugin/views/sort/Date.php b/core/modules/views/src/Plugin/views/sort/Date.php
index 3deae3ed869e..7c2719c6316f 100644
--- a/core/modules/views/src/Plugin/views/sort/Date.php
+++ b/core/modules/views/src/Plugin/views/sort/Date.php
@@ -3,15 +3,15 @@
 namespace Drupal\views\Plugin\views\sort;
 
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Attribute\ViewsSort;
 
 /**
  * Basic sort handler for dates.
  *
  * This handler enables granularity, which is the ability to make dates
  * equivalent based upon nearness.
- *
- * @ViewsSort("date")
  */
+#[ViewsSort("date")]
 class Date extends SortPluginBase {
 
   protected function defineOptions() {
diff --git a/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php b/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
index bbfaa63c0382..50c70ab0dabc 100644
--- a/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
+++ b/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\views\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
 use Drupal\views\Plugin\views\display\DisplayPluginBase;
 use Drupal\views\Plugin\views\HandlerBase;
 use Drupal\views\ViewExecutable;
@@ -9,9 +10,8 @@
 
 /**
  * Handler for GROUP BY on simple numeric fields.
- *
- * @ViewsSort("groupby_numeric")
  */
+#[ViewsSort("groupby_numeric")]
 class GroupByNumeric extends SortPluginBase {
 
   /**
diff --git a/core/modules/views/src/Plugin/views/sort/Random.php b/core/modules/views/src/Plugin/views/sort/Random.php
index c9a552f1b38c..83d18e9c5d7b 100644
--- a/core/modules/views/src/Plugin/views/sort/Random.php
+++ b/core/modules/views/src/Plugin/views/sort/Random.php
@@ -5,12 +5,12 @@
 use Drupal\Core\Cache\CacheableDependencyInterface;
 use Drupal\Core\Cache\UncacheableDependencyTrait;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Attribute\ViewsSort;
 
 /**
  * Handle a random sort.
- *
- * @ViewsSort("random")
  */
+#[ViewsSort("random")]
 class Random extends SortPluginBase implements CacheableDependencyInterface {
 
   use UncacheableDependencyTrait;
diff --git a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php
index bd6cad5a1638..eb6688a36d1e 100644
--- a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php
+++ b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php
@@ -13,8 +13,8 @@
  * Plugins that handle sorting for Views.
  *
  * Sort handlers extend \Drupal\views\Plugin\views\sort:SortPluginBase. They
- * must be annotated with \Drupal\views\Annotation\ViewsSort annotation, and
- * they must be in plugin directory Plugin\views\sort.
+ * must be attributed with the \Drupal\views\Attribute\ViewsSort attribute,
+ * and they must be in plugin directory Plugin\views\sort.
  *
  * @ingroup views_plugins
  * @see plugin_api
diff --git a/core/modules/views/src/Plugin/views/sort/Standard.php b/core/modules/views/src/Plugin/views/sort/Standard.php
index 87849acc37d1..722dee441a99 100644
--- a/core/modules/views/src/Plugin/views/sort/Standard.php
+++ b/core/modules/views/src/Plugin/views/sort/Standard.php
@@ -2,13 +2,14 @@
 
 namespace Drupal\views\Plugin\views\sort;
 
+use Drupal\views\Attribute\ViewsSort;
+
 /**
  * Default implementation of the base sort plugin.
  *
  * @ingroup views_sort_handlers
- *
- * @ViewsSort("standard")
  */
+#[ViewsSort("standard")]
 class Standard extends SortPluginBase {
 
 }
-- 
GitLab