1 views.module 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 Backdrop builds the node portion of the theme registry.

File

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

Code

function views_preprocess_node(&$variables) {
  // The 'view' attribute of the node is added in views_preprocess_node()
  if (!empty($variables['node']->view) && !empty($variables['node']->view->name)) {
    $variables['view'] = $variables['node']->view;
    $variables['theme_hook_suggestions'][] = 'node__view__' . $variables['node']->view->name;
    if (!empty($variables['node']->view->current_display)) {
      $variables['theme_hook_suggestions'][] = 'node__view__' . $variables['node']->view->name . '__' . $variables['node']->view->current_display;

      // If a node is being rendered in a view, and the view does not have a path,
      // prevent Backdrop from accidentally setting the $page variable:
      if ($variables['page'] && $variables['view_mode'] == 'full' && !$variables['view']->display_handler->has_path()) {
        $variables['page'] = FALSE;
      }
    }
  }

  // Allow to alter comments and links based on the settings in the row plugin.
  if (!empty($variables['view']->style_plugin->row_plugin) && get_class($variables['view']->style_plugin->row_plugin) == 'views_plugin_row_node_view') {
    node_row_node_view_preprocess_node($variables);
  }
}