Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. olivero.theme

function olivero_preprocess_comment

Implements hook_preprocess_HOOK() for comment.html.twig.

File

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

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal