From e75e79eb40add53a2b57dbd917bc28b4c332b6cf Mon Sep 17 00:00:00 2001
From: Daniel Wehner <daniel.wehner@erdfisch.de>
Date: Thu, 4 Oct 2012 22:27:16 +0200
Subject: [PATCH] Issue #1802852 by dawehner, damiankloip: Use the alter
 decorator.

---
 lib/Drupal/views/Plugin/Type/JoinManager.php   |  3 ++-
 lib/Drupal/views/Plugin/Type/PluginManager.php |  3 ++-
 lib/Drupal/views/Plugin/Type/WizardManager.php |  3 ++-
 lib/Drupal/views/Tests/UI/DisplayTest.php      | 17 +++++++++++++++++
 views.module                                   | 11 ++++++-----
 views_ui/views_ui.module                       |  7 +++----
 6 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/lib/Drupal/views/Plugin/Type/JoinManager.php b/lib/Drupal/views/Plugin/Type/JoinManager.php
index 0e4801fdbebb..b8608e8faf75 100644
--- a/lib/Drupal/views/Plugin/Type/JoinManager.php
+++ b/lib/Drupal/views/Plugin/Type/JoinManager.php
@@ -9,6 +9,7 @@
 
 use Drupal\Component\Plugin\PluginManagerBase;
 use Drupal\Component\Plugin\Factory\DefaultFactory;
+use Drupal\Core\Plugin\Discovery\AlterDecorator;
 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
 use Drupal\Core\Plugin\Discovery\CacheDecorator;
 
@@ -28,7 +29,7 @@ public function __construct() {
     // @todo Remove this hack in http://drupal.org/node/1708404.
     views_init();
 
-    $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', 'join'), 'views:join', 'views_info');
+    $this->discovery = new CacheDecorator(new AlterDecorator(new AnnotatedClassDiscovery('views', 'join'), 'views_plugins_join'), 'views:join', 'views_info');
     $this->factory = new DefaultFactory($this);
 
     $this->coreModules = views_core_modules();
diff --git a/lib/Drupal/views/Plugin/Type/PluginManager.php b/lib/Drupal/views/Plugin/Type/PluginManager.php
index 4c7ffd9e2379..19df7a849bfd 100644
--- a/lib/Drupal/views/Plugin/Type/PluginManager.php
+++ b/lib/Drupal/views/Plugin/Type/PluginManager.php
@@ -9,6 +9,7 @@
 
 use Drupal\Component\Plugin\PluginManagerBase;
 use Drupal\Component\Plugin\Factory\DefaultFactory;
+use Drupal\Core\Plugin\Discovery\AlterDecorator;
 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
 use Drupal\Core\Plugin\Discovery\CacheDecorator;
 
@@ -28,7 +29,7 @@ public function __construct($type) {
     // @todo Remove this hack in http://drupal.org/node/1708404.
     views_init();
 
-    $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $type), 'views:' . $type, 'views_info');
+    $this->discovery = new CacheDecorator(new AlterDecorator(new AnnotatedClassDiscovery('views', $type), 'views_plugins_' . $type), 'views:' . $type, 'views_info');
     $this->factory = new DefaultFactory($this);
     $this->coreModules = views_core_modules();
     $this->defaults += array(
diff --git a/lib/Drupal/views/Plugin/Type/WizardManager.php b/lib/Drupal/views/Plugin/Type/WizardManager.php
index 336c171c59e3..1586e130fc52 100644
--- a/lib/Drupal/views/Plugin/Type/WizardManager.php
+++ b/lib/Drupal/views/Plugin/Type/WizardManager.php
@@ -9,6 +9,7 @@
 
 use Drupal\Component\Plugin\PluginManagerBase;
 use Drupal\Component\Plugin\Factory\DefaultFactory;
+use Drupal\Core\Plugin\Discovery\AlterDecorator;
 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
 use Drupal\Core\Plugin\Discovery\CacheDecorator;
 
@@ -28,7 +29,7 @@ public function __construct() {
     // @todo Remove this hack in http://drupal.org/node/1708404.
     views_init();
 
-    $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', 'wizard'), 'views:wizard', 'views_info');
+    $this->discovery = new CacheDecorator(new AlterDecorator(new AnnotatedClassDiscovery('views', 'wizard'), 'views_plugins_wizard'), 'views:wizard', 'views_info');
     $this->factory = new DefaultFactory($this);
 
     $this->coreModules = views_core_modules();
diff --git a/lib/Drupal/views/Tests/UI/DisplayTest.php b/lib/Drupal/views/Tests/UI/DisplayTest.php
index 918478b81fa8..55d9781fdb07 100644
--- a/lib/Drupal/views/Tests/UI/DisplayTest.php
+++ b/lib/Drupal/views/Tests/UI/DisplayTest.php
@@ -145,4 +145,21 @@ public function testCloneDisplay() {
     $this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after cloning the new display appears in the UI');
   }
 
+  /**
+   * Tests views_ui_views_plugins_display_alter is altering plugin definitions.
+   */
+  public function testDisplayPluginsAlter() {
+    $definitions = drupal_container()->get('plugin.manager.views.display')->getDefinitions();
+
+    $expected = array(
+      'parent path' => 'admin/structure/views/view',
+      'argument properties' => array('name'),
+    );
+
+    // Test the expected views_ui array exists on each definition.
+    foreach ($definitions as $definition) {
+      $this->assertIdentical($definition['contextual links']['views_ui'], $expected, 'Expected views_ui array found in plugin definition.');
+    }
+  }
+
 }
diff --git a/views.module b/views.module
index aad0d9357eda..e146740a7417 100644
--- a/views.module
+++ b/views.module
@@ -937,7 +937,7 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable
     if (!isset($plugin['contextual_links_locations'])) {
       $plugin['contextual_links_locations'] = array('view');
     }
-    elseif ($plugin['contextual_links_locations'] = array() || $plugin['contextual_links_locations'] == array('')) {
+    elseif ($plugin['contextual_links_locations'] == array() || $plugin['contextual_links_locations'] == array('')) {
       $plugin['contextual_links_locations'] = array();
     }
     else {
@@ -954,14 +954,15 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable
         if (!empty($link['argument properties'])) {
           foreach ($link['argument properties'] as $property) {
             // If the plugin is trying to create an invalid contextual link
-            // (for example, "path/to/{$view->property}", where $view->property
-            // does not exist), we cannot construct the link, so we skip it.
-            if (!property_exists($view, $property)) {
+            // (for example, "path/to/{$view->storage->property}", where
+            // $view->storage->{property} does not exist), we cannot construct
+            // the link, so we skip it.
+            if (!property_exists($view->storage, $property)) {
               $valid = FALSE;
               break;
             }
             else {
-              $args[] = $view->{$property};
+              $args[] = $view->storage->{$property};
             }
           }
         }
diff --git a/views_ui/views_ui.module b/views_ui/views_ui.module
index c3b9d1faf7c2..33e6f68bdcd4 100644
--- a/views_ui/views_ui.module
+++ b/views_ui/views_ui.module
@@ -534,14 +534,13 @@ function views_ui_get_form_wizard_instance($wizard) {
 }
 
 /**
- * Implements hook_views_plugins_alter().
+ * Implements hook_views_plugins_display_alter().
  */
-function views_ui_views_plugins_alter(&$plugins) {
-  // @todo This currently does not work, investigate annotation alters.
+function views_ui_views_plugins_display_alter(&$plugins) {
   // Attach contextual links to each display plugin. The links will point to
   // paths underneath "admin/structure/views/view/{$view->storage->name}" (i.e., paths
   // for editing and performing other contextual actions on the view).
-  foreach ($plugins['display'] as &$display) {
+  foreach ($plugins as &$display) {
     $display['contextual links']['views_ui'] = array(
       'parent path' => 'admin/structure/views/view',
       'argument properties' => array('name'),
-- 
GitLab