function OliveroHooks::preprocessComment

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

Implements hook_preprocess_HOOK() for comment.

Attributes

#[Hook('preprocess_comment')]

File

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

Class

OliveroHooks
Hook implementations for olivero.

Namespace

Drupal\olivero\Hook

Code

public function preprocessComment(&$variables) : void {
  // Getting the node creation time stamp from the comment object.
  $date = $variables['comment']->getCreatedTime();
  // Formatting "created" as "X days ago".
  $variables['created'] = $this->t('@time ago', [
    '@time' => \Drupal::service('date.formatter')->formatInterval(\Drupal::time()->getRequestTime() - $date),
  ]);
}

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