diff --git a/core/modules/forum/css/forum.module.css b/core/modules/forum/css/forum.module.css index 6f2cece..753beb2 100644 --- a/core/modules/forum/css/forum.module.css +++ b/core/modules/forum/css/forum.module.css @@ -3,19 +3,19 @@ * Styling for the Forum module. */ -#forum .description { +.forum .description { font-size: 0.9em; margin: 0.5em; } -#forum td.created, -#forum td.posts, -#forum td.topics, -#forum td.last-reply, -#forum td.replies, -#forum td.pager { +.forum td.created, +.forum td.posts, +.forum td.topics, +.forum td.last-reply, +.forum td.replies, +.forum td.pager { white-space: nowrap; } -#forum .icon{ +.forum .icon{ background-image: url(../../../misc/forum-icons.png); background-repeat: no-repeat; float: left; /* LTR */ @@ -23,34 +23,34 @@ margin: 0 9px 0 0; /* LTR */ width: 24px; } -[dir="rtl"] #forum .icon { +[dir="rtl"] .forum .icon { float: right; margin: 0 0 0 9px; } -#forum .title { +.forum .title { overflow: hidden; } -#forum div.indent { +.forum div.indent { margin-left: 20px; /* LTR */ } -[dir="rtl"] #forum div.indent { +[dir="rtl"] .forum div.indent { margin-left: 0; margin-right: 20px; } -#forum .topic-status-new { +.forum .topic-status-new { background-position: -24px 0; } -#forum .topic-status-hot { +.forum .topic-status-hot { background-position: -48px 0; } -#forum .topic-status-hot-new { +.forum .topic-status-hot-new { background-position: -72px 0; } -#forum .topic-status-sticky { +.forum .topic-status-sticky { background-position: -96px 0; } -#forum .topic-status-closed { +.forum .topic-status-closed { background-position: -120px 0; } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 4593c72..e2a79a5 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Template\Attribute; use Drupal\taxonomy\Entity\Term; use Drupal\field\Field; use Drupal\node\NodeInterface; @@ -74,28 +75,13 @@ function forum_help($path, $arg) { */ function forum_theme() { return array( - 'forums' => array( - 'template' => 'forums', - 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), - ), 'forum_list' => array( 'template' => 'forum-list', - 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL), + 'variables' => array('forums' => NULL, 'term' => NULL), ), 'forum_topic_list' => array( 'template' => 'forum-topic-list', - 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), - ), - 'forum_icon' => array( - 'template' => 'forum-icon', - 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0, 'first_new' => FALSE), - ), - 'forum_submitted' => array( - 'template' => 'forum-submitted', - 'variables' => array('topic' => NULL), - ), - 'forum_form' => array( - 'render element' => 'form', + 'variables' => array('term' => NULL, 'topics' => NULL), ), ); } @@ -616,71 +602,13 @@ function forum_theme_suggestions_forums(array $variables) { } /** - * Prepares variables for forums templates. - * - * Default template: forums.html.twig. - * - * @param array $variables - * An array containing the following elements: - * - forums: An array of all forum objects to display for the given taxonomy - * term ID. If tid = 0 then all the top-level forums are displayed. - * - topics: An array of all the topics in the current forum. - * - parents: An array of taxonomy term objects that are ancestors of the - * current term ID. - * - term: Taxonomy term of the current forum. - * - sortby: One of the following integers indicating the sort criteria: - * - 1: Date - newest first. - * - 2: Date - oldest first. - * - 3: Posts with the most comments first. - * - 4: Posts with the least comments first. - * - forum_per_page: The maximum number of topics to display per page. - */ -function template_preprocess_forums(&$variables) { - $variables['tid'] = $variables['term']->id(); - if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) { - if (!empty($variables['forums'])) { - $variables['forums'] = array( - '#theme' => 'forum_list', - '#forums' => $variables['forums'], - '#parents' => $variables['parents'], - '#tid' => $variables['tid'], - ); - } - else { - $variables['forums'] = array(); - } - - if ($variables['term'] && empty($variables['term']->forum_container->value)) { - $variables['topics'] = array( - '#theme' => 'forum_topic_list', - '#tid' => $variables['tid'], - '#topics' => $variables['topics'], - '#sortby' => $variables['sortby'], - '#forum_per_page' => $variables['forum_per_page'], - ); - } - else { - $variables['topics'] = array(); - } - } - else { - $variables['forums'] = array(); - $variables['topics'] = array(); - } -} - -/** * Prepares variables for forum list templates. * * Default template: forum-list.html.twig. * * @param array $variables * An array containing the following elements: - * - forums: An array of all forum objects to display for the given taxonomy - * term ID. If tid = 0 then all the top-level forums are displayed. - * - parents: An array of taxonomy term objects that are ancestors of the - * current term ID. - * - tid: Taxonomy term ID of the current forum. + * - term: Taxonomy term of the current forum. */ function template_preprocess_forum_list(&$variables) { global $user; @@ -710,17 +638,21 @@ function template_preprocess_forum_list(&$variables) { } $variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics; } - $forum_submitted = array('#theme' => 'forum_submitted', '#topic' => $forum->last_post); - $variables['forums'][$id]->last_reply = drupal_render($forum_submitted); + + if (isset($forum->last_post)) { + $username = array('#theme' => 'username', '#account' => user_load($forum->last_post->uid)); + $variables['forums'][$id]->last_reply_author = drupal_render($username); + $variables['forums'][$id]->last_reply_time = format_interval(REQUEST_TIME - $forum->last_post->created); + } + } $variables['pager'] = array( '#theme' => 'pager', ); - // Give meaning to $tid for themers. $tid actually stands for term ID. - $variables['forum_id'] = $variables['tid']; - unset($variables['tid']); + // Give meaning to $tid for themers as forum_id. + $variables['forum_id'] = $variables['term']->id(); } /** @@ -730,42 +662,59 @@ function template_preprocess_forum_list(&$variables) { * * @param array $variables * An array containing the following elements: - * - tid: Taxonomy term ID of the current forum. + * - term: Taxonomy term of the current forum. * - topics: An array of all the topics in the current forum. - * - forum_per_page: The maximum number of topics to display per page. */ function template_preprocess_forum_topic_list(&$variables) { global $forum_topic_list_header; - $header = ''; + $variables['header'] = array(); if (!empty($forum_topic_list_header)) { // Create the tablesorting header. $ts = tablesort_init($forum_topic_list_header); foreach ($forum_topic_list_header as $cell) { $cell = tablesort_header($cell, $forum_topic_list_header, $ts); - $header .= _theme_table_cell($cell, TRUE); + $data = $cell['data']; + unset($cell['data']); + $variables['header'][] = array( + 'attributes' => new Attribute($cell), + 'data' => $data, + ); } } - $variables['header'] = $header; if (!empty($variables['topics'])) { $row = 0; foreach ($variables['topics'] as $id => $topic) { - $variables['topics'][$id]->icon = array( - '#theme' => 'forum_icon', - '#new_posts' => $topic->new, - '#num_posts' => $topic->comment_count, - '#comment_mode' => $topic->comment_mode, - '#sticky' => $topic->isSticky(), - '#first_new' => $topic->first_new, - ); + + $variables['topics'][$id]->icon = array(); + + if ($topic->comment_mode == COMMENT_CLOSED || $topic->comment_mode == COMMENT_HIDDEN) { + $variables['topics'][$id]->icon_status = 'closed'; + $variables['topics'][$id]->icon_title = t('Closed topic'); + } + elseif ($topic->isSticky()) { + $variables['topics'][$id]->icon_status = 'sticky'; + $variables['topics'][$id]->icon_title = t('Sticky topic'); + } + else { + if ($topic->comment_count > \Drupal::config('forum.settings')->get('topics.hot_threshold')) { + $variables['topics'][$id]->icon_status = $topic->new ? 'hot-new' : 'hot'; + $variables['topics'][$id]->icon_title = $topic->new ? t('Hot topic, new comments') : t('Hot topic'); + } + else { + $variables['topics'][$id]->icon_status = $topic->new ? 'new' : 'default'; + $variables['topics'][$id]->icon_title = $topic->new ? t('New comments') : t('Normal topic'); + } + } + $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; $row++; // We keep the actual tid in forum table, if it's different from the // current tid then it means the topic appears in two forums, one of // them is a shadow copy. - if ($variables['tid'] != $topic->forum_tid) { + if ($variables['term']->id() != $topic->forum_tid) { $variables['topics'][$id]->moved = TRUE; $variables['topics'][$id]->title = check_plain($topic->getTitle()); $variables['topics'][$id]->message = l(t('This topic has been moved'), "forum/$topic->forum_tid"); @@ -775,17 +724,16 @@ function template_preprocess_forum_topic_list(&$variables) { $variables['topics'][$id]->title_link = l($topic->getTitle(), 'node/' . $topic->id()); $variables['topics'][$id]->message = ''; } - $forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array( - 'uid' => $topic->getAuthorId(), - 'name' => $topic->getAuthor()->getUsername(), - 'created' => $topic->getCreatedTime(), - )); - $variables['topics'][$id]->submitted = drupal_render($forum_submitted); - $forum_submitted = array( - '#theme' => 'forum_submitted', - '#topic' => isset($topic->last_reply) ? $topic->last_reply : NULL, - ); - $variables['topics'][$id]->last_reply = drupal_render($forum_submitted); + + $username = array('#theme' => 'username', '#account' => user_load($topic->getAuthorId())); + $variables['topics'][$id]->submitted_author = drupal_render($username); + $variables['topics'][$id]->submitted_time = format_interval(REQUEST_TIME - $topic->getCreatedTime()); + + if (isset($topic->last_reply)) { + $username = array('#theme' => 'username', '#account' => user_load($topic->last_reply->uid)); + $variables['topics'][$id]->last_reply_author = drupal_render($username); + $variables['topics'][$id]->last_reply_time = format_interval(REQUEST_TIME - $topic->last_reply->created); + } $variables['topics'][$id]->new_text = ''; $variables['topics'][$id]->new_url = ''; @@ -801,88 +749,9 @@ function template_preprocess_forum_topic_list(&$variables) { $variables['topics'] = array(); } // Give meaning to $tid for themers. $tid actually stands for term id. - $variables['topic_id'] = $variables['tid']; - unset($variables['tid']); + $variables['topic_id'] = $variables['term']->id(); $variables['pager'] = array( '#theme' => 'pager', ); } - -/** - * Prepares variables for forum icon templates. - * - * Default template: forum-icon.html.twig. - * - * @param 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. - */ -function template_preprocess_forum_icon(&$variables) { - $variables['hot_threshold'] = \Drupal::config('forum.settings')->get('topics.hot_threshold'); - - if ($variables['num_posts'] > $variables['hot_threshold']) { - $icon_status_class = $variables['new_posts'] ? 'hot-new' : 'hot'; - $variables['icon_title'] = $variables['new_posts'] ? t('Hot topic, new comments') : t('Hot topic'); - } - else { - $icon_status_class = $variables['new_posts'] ? 'new' : 'default'; - $variables['icon_title'] = $variables['new_posts'] ? t('New comments') : t('Normal topic'); - } - - if ($variables['comment_mode'] == COMMENT_CLOSED || $variables['comment_mode'] == COMMENT_HIDDEN) { - $icon_status_class = 'closed'; - $variables['icon_title'] = t('Closed topic'); - } - - if ($variables['sticky'] == 1) { - $icon_status_class = 'sticky'; - $variables['icon_title'] = t('Sticky topic'); - } - - $variables['attributes']['class'][] = 'icon'; - $variables['attributes']['class'][] = 'topic-status-' . $icon_status_class; - $variables['attributes']['title'] = $variables['icon_title']; -} - -/** - * 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. - * - * @param array $variables - * An array containing the following elements: - * - topic: The topic object. - */ -function template_preprocess_forum_submitted(&$variables) { - $variables['author'] = ''; - if (isset($variables['topic']->uid)) { - $username = array('#theme' => 'username', '#account' => user_load($variables['topic']->uid)); - $variables['author'] = drupal_render($username); - } - $variables['time'] = isset($variables['topic']->created) ? format_interval(REQUEST_TIME - $variables['topic']->created) : ''; -} - -/** - * Returns HTML for a forum form. - * - * By default this does not alter the appearance of a form at all, but is - * provided as a convenience for themers. - * - * @param $variables - * An associative array containing: - * - form: A render element representing the form. - * - * @ingroup themeable - */ -function theme_forum_form(array $variables) { - return drupal_render_children($variables['form']); -} diff --git a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php index 131c1fe..039d3b6 100644 --- a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php +++ b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php @@ -114,69 +114,55 @@ public static function create(ContainerInterface $container) { * A render array. */ public function forumPage(TermInterface $taxonomy_term) { - // Get forum details. - $taxonomy_term->forums = $this->forumManager->getChildren($this->config->get('vocabulary'), $taxonomy_term->id()); $taxonomy_term->parents = $this->forumManager->getParents($taxonomy_term->id()); - if (empty($taxonomy_term->forum_container->value)) { - // Add RSS feed for forums. - drupal_add_feed('taxonomy/term/' . $taxonomy_term->id() . '/feed', 'RSS - ' . $taxonomy_term->label()); - } - if (empty($taxonomy_term->forum_container->value)) { - $topics = $this->forumManager->getTopics($taxonomy_term->id()); + $topics = $this->forumManager->getTopics($taxonomy_term->id()); + if (!empty($topics)) { + if (empty($taxonomy_term->forum_container->value)) { + // Add RSS feed for forums. + drupal_add_feed('taxonomy/term/' . $taxonomy_term->id() . '/feed', 'RSS - ' . $taxonomy_term->label()); + } + $build = array( + '#theme' => 'forum_topic_list', + '#term' => $taxonomy_term, + '#topics' => $topics, + ); } else { - $topics = ''; + // If we have no topics, this is a container, so render as a forum list. + $build = array( + '#theme' => 'forum_list', + '#term' => $taxonomy_term, + '#forums' => $this->forumManager->getChildren($this->config->get('vocabulary'), $taxonomy_term->id()), + ); } - return $this->build($taxonomy_term->forums, $taxonomy_term, $topics, $taxonomy_term->parents); + + // @todo Make this a library - see https://drupal.org/node/2028113. + $build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/css/forum.module.css'; + return $build; } /** - * Returns forum index page. + * Returns a renderable forum index page array. * * @return array * A render array. */ public function forumIndex() { - $vocabulary = $this->vocabularyStorageController->load($this->config->get('vocabulary')); $index = $this->forumManager->getIndex(); - $build = $this->build($index->forums, $index); + $build = array( + '#theme' => 'forum_list', + '#forums' => $index->forums, + '#term' => $index, + ); if (empty($index->forums)) { // Root of empty forum. $build['#title'] = $this->t('No forums defined'); } else { // Set the page title to forum's vocabulary name. - $build['#title'] = $vocabulary->label(); + $build['#title'] = $this->vocabularyStorageController->load($this->config->get('vocabulary'))->label(); } - return $build; - } - - /** - * Returns a renderable forum index page array. - * - * @param array $forums - * A list of forums. - * @param \Drupal\taxonomy\TermInterface $term - * The taxonomy term of the forum. - * @param array $topics - * The topics of this forum. - * @param array $parents - * The parent forums in relation this forum. - * - * @return array - * A render array. - */ - protected function build($forums, TermInterface $term, $topics = array(), $parents = array()) { - $build = array( - '#theme' => 'forums', - '#forums' => $forums, - '#topics' => $topics, - '#parents' => $parents, - '#term' => $term, - '#sortby' => $this->config->get('topics.order'), - '#forums_per_page' => $this->config->get('topics.page_limit'), - ); // @todo Make this a library - see https://drupal.org/node/2028113. $build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/css/forum.module.css'; return $build; diff --git a/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php b/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php index 56bbb51..4018df0 100644 --- a/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php +++ b/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php @@ -99,7 +99,6 @@ public function form(array $form, array &$form_state) { $form['parent']['#tree'] = TRUE; $form['parent'][0] = $this->forumParentSelect($taxonomy_term->id(), $this->t('Parent')); - $form['#theme'] = 'forum_form'; $this->forumFormType = $this->t('forum'); return $form; } diff --git a/core/modules/forum/templates/forum-icon.html.twig b/core/modules/forum/templates/forum-icon.html.twig deleted file mode 100644 index f3447f8..0000000 --- a/core/modules/forum/templates/forum-icon.html.twig +++ /dev/null @@ -1,25 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display a status icon for a forum post. - * - * Available variables: - * - attributes: HTML attributes to be applied to the wrapper element. - * - class: HTML classes that determine which icon to display. May be one of - * 'hot', 'hot-new', 'new', 'default', 'closed', or 'sticky'. - * - title: Text alternative for the forum icon. - * - icon_title: Text alternative for the forum icon, same as above. - * - new_posts: '1' when this topic contains new posts, otherwise '0'. - * - first_new: '1' when this is the first topic with new posts, otherwise '0'. - * - * @see template_preprocess_forum_icon() - * - * @ingroup themeable - */ -#} - - {% if first_new -%} - - {%- endif %} - {{ icon_title }} - diff --git a/core/modules/forum/templates/forum-list.html.twig b/core/modules/forum/templates/forum-list.html.twig index 5b41f6a..4584535 100644 --- a/core/modules/forum/templates/forum-list.html.twig +++ b/core/modules/forum/templates/forum-list.html.twig @@ -32,7 +32,7 @@ * @ingroup themeable */ #} - +
@@ -73,7 +73,13 @@ {% endif %} - + {% endif %} {% endfor %} diff --git a/core/modules/forum/templates/forum-submitted.html.twig b/core/modules/forum/templates/forum-submitted.html.twig deleted file mode 100644 index 5115b4c..0000000 --- a/core/modules/forum/templates/forum-submitted.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{# -/** - * @file - * Default theme implementation for a forum post submission string. - * - * The submission string indicates when and by whom a topic was submitted. - * - * Available variables: - * - author: The author of the post. - * - time: How long ago the post was created. - * - topic: An object with the raw data of the post. Potentially unsafe. Be - * sure to clean this data before printing. - * - * @see template_preprocess_forum_submitted() - * - * @ingroup themeable - */ -#} -{% if time %} - {{ 'By !author @time ago'|t({'@time': time, '!author': author}) }} -{% else %} - {{ 'n/a'|t }} -{% endif %} diff --git a/core/modules/forum/templates/forum-topic-list.html.twig b/core/modules/forum/templates/forum-topic-list.html.twig index 0e8cd16..a55796c 100644 --- a/core/modules/forum/templates/forum-topic-list.html.twig +++ b/core/modules/forum/templates/forum-topic-list.html.twig @@ -10,7 +10,8 @@ * - pager: The pager to display beneath the table. * - topics: A collection of topics to be displayed. Each topic in topics * contains: - * - icon: The icon to display. + * - icon_status: The status of the icon, used for the icon class. + * - icon_title: The title of the icon. * - moved: A flag to indicate whether the topic has been moved to another * forum. * - title_link: The title of the topic. Safe to output. @@ -31,21 +32,34 @@ * @ingroup themeable */ #} -
{{ 'Forum'|t }} {{ forum.num_posts }}{{ forum.last_reply }} + {% if forum.last_reply_time %} + + {% else %} + {{ 'n/a'|t }} + {% endif %} +
+
- {{ header }} + + {% for cell in header %} + {{ cell.data }} + {% endfor %} + {% for topic in topics %} @@ -59,7 +73,13 @@ {{ topic.new_text }} {% endif %} - + {% endif %} {% endfor %} diff --git a/core/modules/forum/templates/forums.html.twig b/core/modules/forum/templates/forums.html.twig deleted file mode 100644 index afd2490..0000000 --- a/core/modules/forum/templates/forums.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display a forum. - * - * May contain forum containers as well as forum topics. - * - * Available variables: - * - forums: The forums to display (as processed by forum-list.html.twig). - * - topics: The topics to display (as processed by forum-topic-list.html.twig). - * - forums_defined: A flag to indicate that the forums are configured. - * - * @see template_preprocess_forums() - * - * @ingroup themeable - */ -#} -{% if forums_defined %} -
- {{ forums }} - {{ topics }} -
-{% endif %}
- {{ topic.icon }} +
+ {% if topic.first_new -%} + + {%- endif %} + {{ topic.icon_title }} +
{{ topic.title_link }}
- {{ topic.submitted }} + {% if topic.submitted_time %} + + {% else %} + {{ 'n/a'|t }} + {% endif %}
{{ topic.last_reply }} + {% if topic.last_reply_time %} + + {% else %} + {{ 'n/a'|t }} + {% endif %} +