function views_preprocess_node

views_preprocess_node(&$variables)

A theme preprocess function to automatically allow view-based node templates if called from a view.

The 'modules/node.views.inc' file is a better place for this, but we haven't got a chance to load that file before Drupal builds the node portion of the theme registry.

File

core/modules/views/views.module, line 232
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_preprocess_node(&$variables) {
  // The 'view' attribute of the node is added in
  // \Drupal\views\Plugin\views\row\EntityRow::preRender().
  if (!empty($variables['node']->view) && $variables['node']->view->storage->id()) {
    $variables['view'] = $variables['node']->view;
    // If a node is being rendered in a view, and the view does not have a path,
    // prevent drupal from accidentally setting the $page variable:
    if (!empty($variables['view']->current_display)
     && $variables['page']
       && $variables['view_mode'] == 'full'
       && !$variables['view']->display_handler->hasPath()) {
      $variables['page'] = FALSE;
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!views!views.module/function/views_preprocess_node/8.1.x