2013-04-10 20:12:01 +00:00
< ? php
/**
* @ file
* Provide views runtime hooks for node . module .
*/
use Drupal\views\ViewExecutable ;
/**
* Implements hook_views_query_substitutions () .
*/
function node_views_query_substitutions ( ViewExecutable $view ) {
Issue #2061977 by InternetDevels, kim.pepper, ianthomas_uk, herom, rhm50, naveenvalecha, andypost, mandar.harkare, sergeypavlenko, sidharthap, SIz, tkuldeep17: Replace user_access() calls with ->hasPermission() in all core modules except user.
2014-07-12 06:55:56 +00:00
$account = \Drupal :: currentUser ();
2013-04-10 20:12:01 +00:00
return array (
Issue #2061977 by InternetDevels, kim.pepper, ianthomas_uk, herom, rhm50, naveenvalecha, andypost, mandar.harkare, sergeypavlenko, sidharthap, SIz, tkuldeep17: Replace user_access() calls with ->hasPermission() in all core modules except user.
2014-07-12 06:55:56 +00:00
'***ADMINISTER_NODES***' => intval ( $account -> hasPermission ( 'administer nodes' )),
'***VIEW_OWN_UNPUBLISHED_NODES***' => intval ( $account -> hasPermission ( 'view own unpublished content' )),
'***BYPASS_NODE_ACCESS***' => intval ( $account -> hasPermission ( 'bypass node access' )),
2013-04-10 20:12:01 +00:00
);
}
/**
* Implements hook_views_analyze () .
*/
function node_views_analyze ( ViewExecutable $view ) {
$ret = array ();
// Check for something other than the default display:
if ( $view -> storage -> get ( 'base_table' ) == 'node' ) {
Issue #2002650 by mrsinguyen, chertzog, legolasbo, Erik Erskine, rhm50, sandergo90, grisendo, targoo, janstoeckler, maximpodorov, beowulf1416: Improve maintainability by removing unused local variables.
2013-10-02 13:52:21 +00:00
foreach ( $view -> displayHandlers as $display ) {
2013-04-10 20:12:01 +00:00
if ( ! $display -> isDefaulted ( 'access' ) || ! $display -> isDefaulted ( 'filters' )) {
// check for no access control
$access = $display -> getOption ( 'access' );
if ( empty ( $access [ 'type' ]) || $access [ 'type' ] == 'none' ) {
2013-06-24 16:38:32 +00:00
$anonymous_role = entity_load ( 'user_role' , DRUPAL_ANONYMOUS_RID );
$anonymous_has_access = $anonymous_role && $anonymous_role -> hasPermission ( 'access content' );
$authenticated_role = entity_load ( 'user_role' , DRUPAL_AUTHENTICATED_RID );
$authenticated_has_access = $authenticated_role && $authenticated_role -> hasPermission ( 'access content' );
if ( ! $anonymous_has_access || ! $authenticated_has_access ) {
2013-04-10 20:12:01 +00:00
$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 ) {
if ( $filter [ 'table' ] == 'node' && ( $filter [ 'field' ] == 'status' || $filter [ 'field' ] == 'status_extra' )) {
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 [ 'display_title' ])), 'warning' );
}
}
}
}
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 [ 'display_title' ])), 'warning' );
}
}
}
return $ret ;
}