Skip to content
Snippets Groups Projects
Commit e75e79eb authored by Daniel Wehner's avatar Daniel Wehner Committed by Tim Plunkett
Browse files

Issue #1802852 by dawehner, damiankloip: Use the alter decorator.

parent 9d3e8593
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\CacheDecorator;
...@@ -28,7 +29,7 @@ public function __construct() { ...@@ -28,7 +29,7 @@ public function __construct() {
// @todo Remove this hack in http://drupal.org/node/1708404. // @todo Remove this hack in http://drupal.org/node/1708404.
views_init(); 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->factory = new DefaultFactory($this);
$this->coreModules = views_core_modules(); $this->coreModules = views_core_modules();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\CacheDecorator;
...@@ -28,7 +29,7 @@ public function __construct($type) { ...@@ -28,7 +29,7 @@ public function __construct($type) {
// @todo Remove this hack in http://drupal.org/node/1708404. // @todo Remove this hack in http://drupal.org/node/1708404.
views_init(); 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->factory = new DefaultFactory($this);
$this->coreModules = views_core_modules(); $this->coreModules = views_core_modules();
$this->defaults += array( $this->defaults += array(
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\CacheDecorator;
...@@ -28,7 +29,7 @@ public function __construct() { ...@@ -28,7 +29,7 @@ public function __construct() {
// @todo Remove this hack in http://drupal.org/node/1708404. // @todo Remove this hack in http://drupal.org/node/1708404.
views_init(); 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->factory = new DefaultFactory($this);
$this->coreModules = views_core_modules(); $this->coreModules = views_core_modules();
......
...@@ -145,4 +145,21 @@ public function testCloneDisplay() { ...@@ -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'); $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.');
}
}
} }
...@@ -937,7 +937,7 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable ...@@ -937,7 +937,7 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable
if (!isset($plugin['contextual_links_locations'])) { if (!isset($plugin['contextual_links_locations'])) {
$plugin['contextual_links_locations'] = array('view'); $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(); $plugin['contextual_links_locations'] = array();
} }
else { else {
...@@ -954,14 +954,15 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable ...@@ -954,14 +954,15 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable
if (!empty($link['argument properties'])) { if (!empty($link['argument properties'])) {
foreach ($link['argument properties'] as $property) { foreach ($link['argument properties'] as $property) {
// If the plugin is trying to create an invalid contextual link // If the plugin is trying to create an invalid contextual link
// (for example, "path/to/{$view->property}", where $view->property // (for example, "path/to/{$view->storage->property}", where
// does not exist), we cannot construct the link, so we skip it. // $view->storage->{property} does not exist), we cannot construct
if (!property_exists($view, $property)) { // the link, so we skip it.
if (!property_exists($view->storage, $property)) {
$valid = FALSE; $valid = FALSE;
break; break;
} }
else { else {
$args[] = $view->{$property}; $args[] = $view->storage->{$property};
} }
} }
} }
......
...@@ -534,14 +534,13 @@ function views_ui_get_form_wizard_instance($wizard) { ...@@ -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) { function views_ui_views_plugins_display_alter(&$plugins) {
// @todo This currently does not work, investigate annotation alters.
// Attach contextual links to each display plugin. The links will point to // Attach contextual links to each display plugin. The links will point to
// paths underneath "admin/structure/views/view/{$view->storage->name}" (i.e., paths // paths underneath "admin/structure/views/view/{$view->storage->name}" (i.e., paths
// for editing and performing other contextual actions on the view). // 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( $display['contextual links']['views_ui'] = array(
'parent path' => 'admin/structure/views/view', 'parent path' => 'admin/structure/views/view',
'argument properties' => array('name'), 'argument properties' => array('name'),
......
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