From 27b07de8bbc02f654c62cca211c06bd9eb6d9c10 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 16 Mar 2024 17:26:24 +0000
Subject: [PATCH] Issue #3426956 by sorlov, mstrelan, smustgrave: Convert
 ViewsRelationship plugin discovery to attributes

---
 .../views/relationship/NodeTermData.php       |  4 ++--
 .../views/src/Attribute/ViewsRelationship.php | 19 +++++++++++++++++++
 .../src/Plugin/views/relationship/Broken.php  |  4 ++--
 .../views/relationship/EntityReverse.php      |  4 ++--
 .../views/relationship/GroupwiseMax.php       |  4 ++--
 .../relationship/RelationshipPluginBase.php   |  2 +-
 .../Plugin/views/relationship/Standard.php    |  5 +++--
 7 files changed, 31 insertions(+), 11 deletions(-)
 create mode 100644 core/modules/views/src/Attribute/ViewsRelationship.php

diff --git a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php
index 9fa07163678a..9ae0b996c445 100644
--- a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php
+++ b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php
@@ -5,6 +5,7 @@
 use Drupal\Core\Database\Database;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\taxonomy\VocabularyStorageInterface;
+use Drupal\views\Attribute\ViewsRelationship;
 use Drupal\views\Plugin\views\relationship\RelationshipPluginBase;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
@@ -12,9 +13,8 @@
  * Relationship handler to return the taxonomy terms of nodes.
  *
  * @ingroup views_relationship_handlers
- *
- * @ViewsRelationship("node_term_data")
  */
+#[ViewsRelationship("node_term_data")]
 class NodeTermData extends RelationshipPluginBase {
 
   /**
diff --git a/core/modules/views/src/Attribute/ViewsRelationship.php b/core/modules/views/src/Attribute/ViewsRelationship.php
new file mode 100644
index 000000000000..fd8fe1f18dee
--- /dev/null
+++ b/core/modules/views/src/Attribute/ViewsRelationship.php
@@ -0,0 +1,19 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\views\Attribute;
+
+use Drupal\Component\Plugin\Attribute\PluginID;
+
+/**
+ * Defines a Plugin attribute class for views relationship handlers.
+ *
+ * @see \Drupal\views\Plugin\views\relationship\RelationshipPluginBase
+ *
+ * @ingroup views_relationship_handlers
+ */
+#[\Attribute(\Attribute::TARGET_CLASS)]
+class ViewsRelationship extends PluginID {
+
+}
diff --git a/core/modules/views/src/Plugin/views/relationship/Broken.php b/core/modules/views/src/Plugin/views/relationship/Broken.php
index e3285fcd6b0b..8538a217e60f 100644
--- a/core/modules/views/src/Plugin/views/relationship/Broken.php
+++ b/core/modules/views/src/Plugin/views/relationship/Broken.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\views\Plugin\views\relationship;
 
+use Drupal\views\Attribute\ViewsRelationship;
 use Drupal\views\Plugin\views\BrokenHandlerTrait;
 
 /**
  * A special handler to take the place of missing or broken handlers.
  *
  * @ingroup views_relationship_handlers
- *
- * @ViewsRelationship("broken")
  */
+#[ViewsRelationship("broken")]
 class Broken extends RelationshipPluginBase {
   use BrokenHandlerTrait;
 
diff --git a/core/modules/views/src/Plugin/views/relationship/EntityReverse.php b/core/modules/views/src/Plugin/views/relationship/EntityReverse.php
index 64c3d7055784..123b5c0dd4bb 100644
--- a/core/modules/views/src/Plugin/views/relationship/EntityReverse.php
+++ b/core/modules/views/src/Plugin/views/relationship/EntityReverse.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\views\Plugin\views\relationship;
 
+use Drupal\views\Attribute\ViewsRelationship;
 use Drupal\views\Plugin\ViewsHandlerManager;
 use Drupal\views\Views;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -10,9 +11,8 @@
  * A relationship handlers which reverse entity references.
  *
  * @ingroup views_relationship_handlers
- *
- * @ViewsRelationship("entity_reverse")
  */
+#[ViewsRelationship("entity_reverse")]
 class EntityReverse extends RelationshipPluginBase {
 
   /**
diff --git a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php
index be72d1da3693..61cabe3e26f8 100644
--- a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php
+++ b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Database\Query\AlterableInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Attribute\ViewsRelationship;
 use Drupal\views\Views;
 use Drupal\views\Entity\View;
 
@@ -56,9 +57,8 @@
  * in the same way as node_comment_statistics.
  *
  * @ingroup views_relationship_handlers
- *
- * @ViewsRelationship("groupwise_max")
  */
+#[ViewsRelationship("groupwise_max")]
 class GroupwiseMax extends RelationshipPluginBase {
 
   /**
diff --git a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
index 8774b81cef14..deafd82f4057 100644
--- a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
+++ b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php
@@ -15,7 +15,7 @@
  *
  * Relationship handlers extend
  * \Drupal\views\Plugin\views\relationship\RelationshipPluginBase. They must
- * be annotated with \Drupal\views\Annotation\ViewsRelationship annotation,
+ * be attributed with \Drupal\views\Attribute\ViewsRelationship attribute,
  * and they must be in namespace directory Plugin\views\relationship.
  *
  * @ingroup views_plugins
diff --git a/core/modules/views/src/Plugin/views/relationship/Standard.php b/core/modules/views/src/Plugin/views/relationship/Standard.php
index 817a9ad7af26..3637d57189e7 100644
--- a/core/modules/views/src/Plugin/views/relationship/Standard.php
+++ b/core/modules/views/src/Plugin/views/relationship/Standard.php
@@ -2,13 +2,14 @@
 
 namespace Drupal\views\Plugin\views\relationship;
 
+use Drupal\views\Attribute\ViewsRelationship;
+
 /**
  * Default implementation of the base relationship plugin.
  *
  * @ingroup views_relationship_handlers
- *
- * @ViewsRelationship("standard")
  */
+#[ViewsRelationship("standard")]
 class Standard extends RelationshipPluginBase {
 
 }
-- 
GitLab