function OliveroHooks::preprocessNode

Same name and namespace in other branches
  1. main core/themes/olivero/src/Hook/OliveroHooks.php \Drupal\olivero\Hook\OliveroHooks::preprocessNode()

Implements hook_preprocess_HOOK() for node.

Attributes

#[Hook('preprocess_node')]

File

core/themes/olivero/src/Hook/OliveroHooks.php, line 68

Class

OliveroHooks
Hook implementations for olivero.

Namespace

Drupal\olivero\Hook

Code

public function preprocessNode(&$variables) : void {
  // Remove the "Add new comment" link on teasers or when the comment form is
  // displayed on the page.
  if ($variables['view_mode'] === 'teaser' || !empty($variables['content']['comments']['comment_form'])) {
    unset($variables['content']['links']['comment']['#links']['comment-add']);
  }
  // Apply custom date formatter to "date" field.
  if (!empty($variables['date']) && !empty($variables['display_submitted']) && $variables['display_submitted'] === TRUE) {
    $variables['date'] = \Drupal::service('date.formatter')->format($variables['node']->getCreatedTime(), 'olivero_medium');
  }
  // Pass layout variable to template if content type is article in full view
  // mode. This is then used in the template to create a BEM style CSS class
  // to control the layout.
  if ($variables['node']->bundle() === 'article' && $variables['view_mode'] === 'full') {
    $variables['layout'] = 'content-narrow';
  }
}

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