Commit e75e79eb authored by dawehner's avatar dawehner Committed by tim.plunkett

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

parent 9d3e8593
......@@ -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();
......
......@@ -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(
......
......@@ -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();
......
......@@ -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.');
}
}
}
......@@ -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};
}
}
}
......
......@@ -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'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment