function template_preprocess_forum_icon

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

Prepares variables for forum icon templates.

Default template: forum-icon.html.twig.

Parameters

array $variables: An array containing the following elements:

  • new_posts: Indicates whether or not the topic contains new posts.
  • num_posts: The total number of posts in all topics.
  • comment_mode: An integer indicating whether comments are open, closed, or hidden.
  • sticky: Indicates whether the topic is sticky.
  • first_new: Indicates whether this is the first topic with new posts.

File

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

Code

function template_preprocess_forum_icon(&$variables) {
    $variables['hot_threshold'] = \Drupal::config('forum.settings')->get('topics.hot_threshold');
    if ($variables['num_posts'] > $variables['hot_threshold']) {
        $variables['icon_status'] = $variables['new_posts'] ? 'hot-new' : 'hot';
        $variables['icon_title'] = $variables['new_posts'] ? t('Hot topic, new comments') : t('Hot topic');
    }
    else {
        $variables['icon_status'] = $variables['new_posts'] ? 'new' : 'default';
        $variables['icon_title'] = $variables['new_posts'] ? t('New comments') : t('Normal topic');
    }
    if ($variables['comment_mode'] == CommentItemInterface::CLOSED || $variables['comment_mode'] == CommentItemInterface::HIDDEN) {
        $variables['icon_status'] = 'closed';
        $variables['icon_title'] = t('Closed topic');
    }
    if ($variables['sticky'] == 1) {
        $variables['icon_status'] = 'sticky';
        $variables['icon_title'] = t('Sticky topic');
    }
    $variables['attributes']['title'] = $variables['icon_title'];
}

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