class ViewsThemeHooks

Hook implementations for views.

Hierarchy

Expanded class hierarchy of ViewsThemeHooks

File

core/modules/views/src/Hook/ViewsThemeHooks.php, line 10

Namespace

Drupal\views\Hook
View source
class ViewsThemeHooks {
  
  /**
   * Implements hook_preprocess_HOOK().
   *
   * Allows view-based node templates if called from a view.
   */
  public function preprocessNode(&$variables) : void {
    // 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;
      // The view variable is deprecated.
      $variables['deprecations']['view'] = "'view' is deprecated in drupal:11.1.0 and is removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3459903";
      // 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;
      }
    }
  }
  
  /**
   * Implements hook_preprocess_HOOK().
   *
   * Allows view-based comment templates if called from a view.
   */
  public function preprocessComment(&$variables) : void {
    // The view data is added to the comment in
    // \Drupal\views\Plugin\views\row\EntityRow::preRender().
    if (!empty($variables['comment']->view) && $variables['comment']->view->storage
      ->id()) {
      $variables['view'] = $variables['comment']->view;
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
ViewsThemeHooks::preprocessComment public function Implements hook_preprocess_HOOK().
ViewsThemeHooks::preprocessNode public function Implements hook_preprocess_HOOK().

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