You are here

function olivero_preprocess_node in Drupal 10

Same name and namespace in other branches
  1. 9 core/themes/olivero/olivero.theme \olivero_preprocess_node()

Implements hook_preprocess_HOOK() for node.html.twig.

File

core/themes/olivero/olivero.theme, line 97
Functions to support theming in the Olivero theme.

Code

function olivero_preprocess_node(&$variables) {

  // Remove the "Add new comment" link on teasers or when the comment form is
  // displayed on the page.
  if ($variables['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';
  }
}