function olivero_preprocess_node

Same name and namespace in other branches
  1. 10 core/themes/olivero/olivero.theme \olivero_preprocess_node()
  2. 11.x core/themes/olivero/olivero.theme \olivero_preprocess_node()

Implements hook_preprocess_HOOK() for node.html.twig.

File

core/themes/olivero/olivero.theme, line 91

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';
    }
}

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