Commit acf577ed authored by catch's avatar catch

Issue #1827286 by dawehner, damiankloip: Fixed hook_views_analyze() is missing...

Issue #1827286 by dawehner, damiankloip: Fixed hook_views_analyze() is missing from hook_hook_info() so never gets executed.
parent b36b17ed
......@@ -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');
}
}
}
......
......@@ -30,6 +30,8 @@ public static function getInfo() {
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 @@ function testAnalyzeBasic() {
$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'));
}
......
<?php
/**
* @file
* Provides views data and hooks for views_test_data module.
*/
use Drupal\views\Analyzer;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_analyze().
*/
function views_test_data_views_analyze(ViewExecutable $view) {
$ret = array();
$ret[] = Analyzer::formatMessage(t('Test ok message'), 'ok');
$ret[] = Analyzer::formatMessage(t('Test warning message'), 'warning');
$ret[] = Analyzer::formatMessage(t('Test error message'), 'error');
return $ret;
}
......@@ -897,6 +897,9 @@ function views_hook_info() {
$hooks['views_form_substitutions'] = array(
'group' => 'views',
);
$hooks['views_analyze'] = array(
'group' => 'views',
);
return $hooks;
}
......
......@@ -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');
}
}
}
......
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