function template_preprocess_forum_submitted

Same name and namespace in other branches
  1. 7.x modules/forum/forum.module \template_preprocess_forum_submitted()
  2. 9 core/modules/forum/forum.module \template_preprocess_forum_submitted()
  3. 10 core/modules/forum/forum.module \template_preprocess_forum_submitted()
  4. 11.x core/modules/forum/forum.module \template_preprocess_forum_submitted()

Prepares variables for forum submission information templates.

The submission information will be displayed in the forum list and topic list.

Default template: forum-submitted.html.twig.

Parameters

array $variables: An array containing the following elements:

  • topic: The topic object.

File

core/modules/forum/forum.module, line 638

Code

function template_preprocess_forum_submitted(&$variables) {
    $variables['author'] = '';
    if (isset($variables['topic']->uid)) {
        $username = [
            '#theme' => 'username',
            '#account' => User::load($variables['topic']->uid),
        ];
        $variables['author'] = \Drupal::service('renderer')->render($username);
    }
    $variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date.formatter')->formatTimeDiffSince($variables['topic']->created) : '';
}

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