From acf577ed72b1da1db258e1bae8aaa348e55b2778 Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 10 Jan 2013 17:14:16 +0000 Subject: [PATCH] Issue #1827286 by dawehner, damiankloip: Fixed hook_views_analyze() is missing from hook_hook_info() so never gets executed. --- core/modules/node/node.views.inc | 13 ++++++----- .../lib/Drupal/views/Tests/AnalyzeTest.php | 9 +++++++- .../views_test_data/views_test_data.views.inc | 22 +++++++++++++++++++ core/modules/views/views.module | 3 +++ core/modules/views/views_ui/views_ui.module | 4 ++-- 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 core/modules/views/tests/views_test_data/views_test_data.views.inc diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index a67b870e2ac..8f8d75f193e 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -8,6 +8,7 @@ */ use Drupal\views\Analyzer; +use Drupal\views\ViewExecutable; /** * Implements hook_views_data(). @@ -681,10 +682,10 @@ function node_views_query_substitutions() { /** * Implements hook_views_analyze(). */ -function node_views_analyze($view) { +function node_views_analyze(ViewExecutable $view) { $ret = array(); // Check for something other than the default display: - if ($view->base_table == 'node') { + if ($view->storage->get('base_table') == 'node') { foreach ($view->displayHandlers as $id => $display) { if (!$display->isDefaulted('access') || !$display->isDefaulted('filters')) { // check for no access control @@ -703,7 +704,7 @@ function node_views_analyze($view) { $roles[$role->rid] = $role; } if (!($roles['anonymous']->safe && $roles['authenticated']->safe)) { - $ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display['display_title'])), 'warning'); + $ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display['display_title'])), 'warning'); } $filters = $display->getOption('filters'); foreach ($filters as $filter) { @@ -711,15 +712,15 @@ function node_views_analyze($view) { continue 2; } } - $ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display['display_title'])), 'warning'); + $ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display['display_title'])), 'warning'); } } } } - foreach ($view->display as $id => $display) { + foreach ($view->displayHandlers as $display) { if ($display->getPluginId() == 'page') { if ($display->getOption('path') == 'node/%') { - $ret[] = Analyzer::formatMessage(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display['display_title'])), 'warning'); + $ret[] = Analyzer::formatMessage(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display['display_title'])), 'warning'); } } } diff --git a/core/modules/views/lib/Drupal/views/Tests/AnalyzeTest.php b/core/modules/views/lib/Drupal/views/Tests/AnalyzeTest.php index f5497f2191a..cd0e317151c 100644 --- a/core/modules/views/lib/Drupal/views/Tests/AnalyzeTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/AnalyzeTest.php @@ -30,6 +30,8 @@ class AnalyzeTest extends ViewTestBase { public function setUp() { parent::setUp(); + $this->enableViewsTestModule(); + // Add an admin user will full rights; $this->admin = $this->drupalCreateUser(array('administer views')); } @@ -45,10 +47,15 @@ class AnalyzeTest extends ViewTestBase { $this->drupalGet('admin/structure/views/view/frontpage/edit'); $this->assertLink(t('analyze view')); - // This redirects the user to the form. + // This redirects the user to the analyze form. $this->clickLink(t('analyze view')); $this->assertText(t('View analysis')); + foreach (array('ok', 'warning', 'error') as $type) { + $xpath = $this->xpath('//div[contains(@class, :class)]', array(':class' => $type)); + $this->assertTrue(count($xpath), format_string('Analyse messages with @type found', array('@type' => $type))); + } + // This redirects the user back to the main views edit page. $this->drupalPost(NULL, array(), t('Ok')); } diff --git a/core/modules/views/tests/views_test_data/views_test_data.views.inc b/core/modules/views/tests/views_test_data/views_test_data.views.inc new file mode 100644 index 00000000000..428e93b1481 --- /dev/null +++ b/core/modules/views/tests/views_test_data/views_test_data.views.inc @@ -0,0 +1,22 @@ + 'views', ); + $hooks['views_analyze'] = array( + 'group' => 'views', + ); return $hooks; } diff --git a/core/modules/views/views_ui/views_ui.module b/core/modules/views/views_ui/views_ui.module index e3e93628b54..7552f631c40 100644 --- a/core/modules/views/views_ui/views_ui.module +++ b/core/modules/views/views_ui/views_ui.module @@ -628,7 +628,7 @@ function views_ui_library_alter(&$libraries, $module) { * There are other analysis tools in core specific sections, such as * node.views.inc as well. */ -function views_ui_views_analyze($view) { +function views_ui_views_analyze(ViewExecutable $view) { $ret = array(); // Check for something other than the default display: if (count($view->displayHandlers) < 2) { @@ -644,7 +644,7 @@ function views_ui_views_analyze($view) { if ($display->hasPath() && $path = $display->getOption('path')) { $normal_path = drupal_container()->get('path.alias_manager.cached')->getSystemPath($path); if ($path != $normal_path) { - $ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array('%display' => $display['display_title'])), 'warning'); + $ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array('%display' => $display->display['display_title'])), 'warning'); } } }