function olivero_preprocess_node

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

Implements hook_preprocess_HOOK() for node.html.twig.

File

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

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['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.