function views_ui_views_analyze

Same name in other branches
  1. 9 core/modules/views_ui/views_ui.module \views_ui_views_analyze()
  2. 10 core/modules/views_ui/views_ui.module \views_ui_views_analyze()
  3. 11.x core/modules/views_ui/views_ui.module \views_ui_views_analyze()

Implements hook_views_analyze().

This is the basic views analysis that checks for very minimal problems. There are other analysis tools in core specific sections, such as node.views.inc as well.

File

core/modules/views_ui/views_ui.module, line 313

Code

function views_ui_views_analyze(ViewExecutable $view) {
    $ret = [];
    // Check for something other than the default display:
    if (count($view->displayHandlers) < 2) {
        $ret[] = Analyzer::formatMessage(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning');
    }
    // If a display has a path, check that it does not match an existing path
    // alias. This results in the path alias not working.
    foreach ($view->displayHandlers as $display) {
        if (empty($display)) {
            continue;
        }
        if ($display->hasPath() && ($path = $display->getOption('path'))) {
            $normal_path = \Drupal::service('path_alias.manager')->getPathByAlias($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.', [
                    '%display' => $display->display['display_title'],
                ]), 'warning');
            }
        }
    }
    return $ret;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.