From d8bfd3b9f6f1fde59fce51a0cca603cfd55f5c6e Mon Sep 17 00:00:00 2001
From: Daniel Wehner <daniel.wehner@erdfisch.de>
Date: Sat, 28 Jul 2012 10:24:36 -0500
Subject: [PATCH] Use annotation for relationships

---
 .../views/Plugins/views/relationship/GroupwiseMax.php |  9 ++++++++-
 .../views/relationship/RelationshipPluginBase.php     | 11 +++++++++--
 modules/book.views.inc                                |  4 ++--
 modules/comment.views.inc                             |  6 +++---
 modules/file.views.inc                                |  2 +-
 modules/image.views.inc                               |  2 +-
 modules/node.views.inc                                |  8 ++++----
 modules/statistics.views.inc                          |  2 +-
 modules/taxonomy.views.inc                            |  4 ++--
 .../views_handler_relationship_node_term_data.inc     |  3 ++-
 modules/translation.views.inc                         |  2 +-
 .../views_handler_relationship_translation.inc        |  3 ++-
 modules/user.views.inc                                |  2 +-
 views.api.php                                         | 11 ++++-------
 14 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/lib/Drupal/views/Plugins/views/relationship/GroupwiseMax.php b/lib/Drupal/views/Plugins/views/relationship/GroupwiseMax.php
index 31cc62f58b77..732677a393e5 100644
--- a/lib/Drupal/views/Plugins/views/relationship/GroupwiseMax.php
+++ b/lib/Drupal/views/Plugins/views/relationship/GroupwiseMax.php
@@ -10,6 +10,7 @@
 use Drupal\Core\Database\Query\AlterableInterface;
 use Drupal\views\View;
 use Drupal\views\JoinSubquery;
+use Drupal\Core\Annotation\Plugin;
 
 /**
  * Relationship handler that allows a groupwise maximum of the linked in table.
@@ -59,7 +60,13 @@
  *
  * @ingroup views_relationship_handlers
  */
-class GroupwiseMax extends relationshipPluginBase {
+
+/**
+ * @plugin(
+ *   plugin_id = "groupwise_max"
+ * )
+ */
+class GroupwiseMax extends RelationshipPluginBase {
 
   /**
    * Defines default values for options.
diff --git a/lib/Drupal/views/Plugins/views/relationship/RelationshipPluginBase.php b/lib/Drupal/views/Plugins/views/relationship/RelationshipPluginBase.php
index 9fe21aa0d0c1..34132c430ec1 100644
--- a/lib/Drupal/views/Plugins/views/relationship/RelationshipPluginBase.php
+++ b/lib/Drupal/views/Plugins/views/relationship/RelationshipPluginBase.php
@@ -7,8 +7,9 @@
 
 namespace Drupal\views\Plugins\views\relationship;
 
-use Drupal\views\Plugins\views\Plugin;
+use Drupal\views\Plugins\views\Handler;
 use Drupal\views\Join;
+use Drupal\Core\Annotation\Plugin;
 
 /**
  * @defgroup views_relationship_handlers Views relationship handlers
@@ -40,7 +41,13 @@
  *
  * @ingroup views_relationship_handlers
  */
-class RelationshipPluginBase extends Plugin {
+
+/**
+ * @Plugin(
+ *   plugin_id = "standard"
+ * )
+ */
+class RelationshipPluginBase extends Handler {
   /**
    * Init handler to let relationships live on tables other than
    * the table they operate on.
diff --git a/modules/book.views.inc b/modules/book.views.inc
index 61751e8ee7d6..e814068a06db 100644
--- a/modules/book.views.inc
+++ b/modules/book.views.inc
@@ -27,7 +27,7 @@ function book_views_data() {
     'help' => t('The book the node is in.'),
     'relationship' => array(
       'base' => 'node',
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'label' => t('Book'),
     ),
     // There is no argument here; if you need an argument, add the relationship
@@ -107,7 +107,7 @@ function book_views_data() {
     'relationship' => array(
       'base' => 'node',
       'base field' => 'nid',
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'label' => t('Book parent'),
     ),
   );
diff --git a/modules/comment.views.inc b/modules/comment.views.inc
index ccc7ebe10d9c..b6dec9876419 100644
--- a/modules/comment.views.inc
+++ b/modules/comment.views.inc
@@ -402,7 +402,7 @@ function comment_views_data() {
       'help' => t('The parent comment.'),
       'base' => 'comment',
       'base field' => 'cid',
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'label' => t('Parent comment'),
     ),
   );
@@ -500,7 +500,7 @@ function comment_views_data() {
       'group' => t('Comment'),
       'base' => 'comment',
       'base field' => 'cid',
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'label' => t('Last Comment'),
     ),
   );
@@ -596,7 +596,7 @@ function comment_views_data_alter(&$data) {
       'base' => 'comment',
       'base field' => 'nid',
       'relationship field' => 'nid',
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
     ),
   );
 
diff --git a/modules/file.views.inc b/modules/file.views.inc
index 85569385e945..394ebf00406c 100644
--- a/modules/file.views.inc
+++ b/modules/file.views.inc
@@ -20,7 +20,7 @@ function file_field_views_data($field) {
   foreach ($data as $table_name => $table_data) {
     // Add the relationship only on the fid field.
     $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'base' => 'file_managed',
       'entity type' => 'file',
       'base field' => 'fid',
diff --git a/modules/image.views.inc b/modules/image.views.inc
index 6fc6565b6381..ef7876e2ad1e 100644
--- a/modules/image.views.inc
+++ b/modules/image.views.inc
@@ -20,7 +20,7 @@ function image_field_views_data($field) {
   foreach ($data as $table_name => $table_data) {
     // Add the relationship only on the fid field.
     $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
-      'handler' => 'views_handler_relationship',
+      'plugin_id' => 'standard',
       'base' => 'file_managed',
       'base field' => 'fid',
       'label' => t('image from !field_name', array('!field_name' => $field['field_name'])),
diff --git a/modules/node.views.inc b/modules/node.views.inc
index 14931c5064d0..09703ea81391 100644
--- a/modules/node.views.inc
+++ b/modules/node.views.inc
@@ -380,7 +380,7 @@ function node_views_data() {
     'relationship' => array(
       'title' => t('Author'),
       'help' => t('Relate content to the user who created it.'),
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'users',
       'field' => 'uid',
       'label' => t('author'),
@@ -450,7 +450,7 @@ function node_views_data() {
     'title' => t('User'),
     'help' => t('Relate a content revision to the user who created the revision.'),
     'relationship' => array(
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'users',
       'base field' => 'uid',
       'label' => t('revision user'),
@@ -473,14 +473,14 @@ function node_views_data() {
     ),
     // Information for accepting a nid as a filter
     'filter' => array(
-      'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
+      'plugin_id' => 'numeric',
     ),
     // Information for sorting on a nid.
     'sort' => array(
       'plugin_id' => 'standard',
     ),
     'relationship' => array(
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'node',
       'base field' => 'vid',
       'title' => t('Content'),
diff --git a/modules/statistics.views.inc b/modules/statistics.views.inc
index b33b84ab72de..1b9cf2b006f9 100644
--- a/modules/statistics.views.inc
+++ b/modules/statistics.views.inc
@@ -220,7 +220,7 @@ function statistics_views_data() {
     'title' => t('User'),
     'help' => t('The user who visited the site.'),
     'relationship' => array(
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'users',
       'base field' => 'uid',
      ),
diff --git a/modules/taxonomy.views.inc b/modules/taxonomy.views.inc
index 22d839786bb3..9c6237675e3e 100644
--- a/modules/taxonomy.views.inc
+++ b/modules/taxonomy.views.inc
@@ -292,7 +292,7 @@ function taxonomy_views_data() {
     'title' => t('Content with term'),
     'help' => t('Relate all content tagged with a term.'),
     'relationship' => array(
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'node',
       'base field' => 'nid',
       'label' => t('node'),
@@ -436,7 +436,7 @@ function taxonomy_field_views_data($field) {
 
     // Add the relationship only on the tid field.
     $data[$table_name][$field['field_name'] . '_tid']['relationship'] = array(
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'taxonomy_term_data',
       'base field' => 'tid',
       'label' => t('term from !field_name', array('!field_name' => $field['field_name'])),
diff --git a/modules/taxonomy/views_handler_relationship_node_term_data.inc b/modules/taxonomy/views_handler_relationship_node_term_data.inc
index b7698b05ef87..8d01ff64dd92 100644
--- a/modules/taxonomy/views_handler_relationship_node_term_data.inc
+++ b/modules/taxonomy/views_handler_relationship_node_term_data.inc
@@ -6,13 +6,14 @@
  */
 
 use Drupal\views\Join;
+use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
 
 /**
  * Relationship handler to return the taxonomy terms of nodes.
  *
  * @ingroup views_relationship_handlers
  */
-class views_handler_relationship_node_term_data extends views_handler_relationship  {
+class views_handler_relationship_node_term_data extends RelationshipPluginBase  {
   function init(&$view, &$options) {
     parent::init($view, $options);
 
diff --git a/modules/translation.views.inc b/modules/translation.views.inc
index 030560f291d8..cb90205bf274 100644
--- a/modules/translation.views.inc
+++ b/modules/translation.views.inc
@@ -46,7 +46,7 @@ function translation_views_data_alter(&$data) {
       'help' => t('The source that this content was translated from.'),
       'base' => 'node',
       'base field' => 'nid',
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'label' => t('Source translation'),
     ),
   );
diff --git a/modules/translation/views_handler_relationship_translation.inc b/modules/translation/views_handler_relationship_translation.inc
index 6dd9f05f0972..ef27dca7cf17 100644
--- a/modules/translation/views_handler_relationship_translation.inc
+++ b/modules/translation/views_handler_relationship_translation.inc
@@ -6,6 +6,7 @@
  */
 
 use Drupal\views\Join;
+use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
 
 /**
  * Handles relationships for content translation sets and provides multiple
@@ -13,7 +14,7 @@
  *
  * @ingroup views_relationship_handlers
  */
-class views_handler_relationship_translation extends views_handler_relationship {
+class views_handler_relationship_translation extends RelationshipPluginBase {
   function option_definition() {
     $options = parent::option_definition();
     $options['language'] = array('default' => 'current');
diff --git a/modules/user.views.inc b/modules/user.views.inc
index 301d27f35d0f..54ad20522b3f 100644
--- a/modules/user.views.inc
+++ b/modules/user.views.inc
@@ -64,7 +64,7 @@ function user_views_data() {
     'relationship' => array(
       'title' => t('Content authored'),
       'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
-      'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
+      'plugin_id' => 'standard',
       'base' => 'node',
       'base field' => 'uid',
       'field' => 'uid',
diff --git a/views.api.php b/views.api.php
index 1297e1358392..92f138a5970d 100644
--- a/views.api.php
+++ b/views.api.php
@@ -372,13 +372,10 @@ function hook_views_data() {
     // other direction, use hook_views_data_alter(), or use the 'implicit' join
     // method described above.
     'relationship' => array(
-      'base' => 'node', // The name of the table to join with.
-      'base field' => 'nid', // The name of the field on the joined table.
-      // 'field' => 'nid' -- see hook_views_data_alter(); not needed here.
-      'handler' => 'views_handler_relationship',
-      'label' => t('Default label for the relationship'),
-      'title' => t('Title shown when adding the relationship'),
-      'help' => t('More information on this relationship'),
+      'base' => 'node', // The name of the table to join with
+      'field' => 'nid', // The name of the field to join with
+      'plugin_id' => 'standard',
+      'label' => t('Example node'),
     ),
   );
 
-- 
GitLab