annotate core/modules/node/node.views_execution.inc @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Provide views runtime hooks for node.module.
Chris@0 6 */
Chris@0 7
Chris@0 8 use Drupal\user\RoleInterface;
Chris@0 9 use Drupal\views\ViewExecutable;
Chris@0 10 use Drupal\user\Entity\Role;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Implements hook_views_query_substitutions().
Chris@0 14 */
Chris@0 15 function node_views_query_substitutions(ViewExecutable $view) {
Chris@0 16 $account = \Drupal::currentUser();
Chris@0 17 return [
Chris@0 18 '***ADMINISTER_NODES***' => intval($account->hasPermission('administer nodes')),
Chris@0 19 '***VIEW_OWN_UNPUBLISHED_NODES***' => intval($account->hasPermission('view own unpublished content')),
Chris@0 20 '***BYPASS_NODE_ACCESS***' => intval($account->hasPermission('bypass node access')),
Chris@0 21 ];
Chris@0 22 }
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Implements hook_views_analyze().
Chris@0 26 */
Chris@0 27 function node_views_analyze(ViewExecutable $view) {
Chris@0 28 $ret = [];
Chris@0 29 // Check for something other than the default display:
Chris@0 30 if ($view->storage->get('base_table') == 'node') {
Chris@0 31 foreach ($view->displayHandlers as $display) {
Chris@0 32 if (!$display->isDefaulted('access') || !$display->isDefaulted('filters')) {
Chris@0 33 // check for no access control
Chris@0 34 $access = $display->getOption('access');
Chris@0 35 if (empty($access['type']) || $access['type'] == 'none') {
Chris@0 36 $anonymous_role = Role::load(RoleInterface::ANONYMOUS_ID);
Chris@0 37 $anonymous_has_access = $anonymous_role && $anonymous_role->hasPermission('access content');
Chris@0 38 $authenticated_role = Role::load(RoleInterface::AUTHENTICATED_ID);
Chris@0 39 $authenticated_has_access = $authenticated_role && $authenticated_role->hasPermission('access content');
Chris@0 40 if (!$anonymous_has_access || !$authenticated_has_access) {
Chris@0 41 $ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', ['%display' => $display->display['display_title']]), 'warning');
Chris@0 42 }
Chris@0 43 $filters = $display->getOption('filters');
Chris@0 44 foreach ($filters as $filter) {
Chris@0 45 if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
Chris@0 46 continue 2;
Chris@0 47 }
Chris@0 48 }
Chris@0 49 $ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', ['%display' => $display->display['display_title']]), 'warning');
Chris@0 50 }
Chris@0 51 }
Chris@0 52 }
Chris@0 53 }
Chris@0 54 foreach ($view->displayHandlers as $display) {
Chris@0 55 if ($display->getPluginId() == 'page') {
Chris@0 56 if ($display->getOption('path') == 'node/%') {
Chris@0 57 $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.', ['%display' => $display->display['display_title']]), 'warning');
Chris@0 58 }
Chris@0 59 }
Chris@0 60 }
Chris@0 61
Chris@0 62 return $ret;
Chris@0 63 }