diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 9b405b2..d87a4a4 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -82,10 +82,6 @@ function forum_theme() { 'template' => 'forum-list', 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => 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), @@ -628,6 +624,7 @@ function forum_theme_suggestions_forums(array $variables) { * - forum_per_page: The maximum number of topics to display per page. */ function template_preprocess_forums(&$variables) { + $variables['topics_pager'] = array(); $variables['tid'] = $variables['term']->id(); if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) { if (!empty($variables['forums'])) { @@ -643,12 +640,105 @@ function template_preprocess_forums(&$variables) { } 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'], + global $forum_topic_list_header; + + $table = array( + '#theme' => 'table__forum_topic_list', + '#attributes' => array('id' => 'forum-topic-' . $variables['tid']), + '#header' => array(), + '#rows' => array(), + ); + + if (!empty($forum_topic_list_header)) { + $table['#header'] = $forum_topic_list_header; + } + + if (!empty($variables['topics'])) { + 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, + ); + + // 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) { + $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"); + } + else { + $variables['topics'][$id]->moved = FALSE; + $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); + + $variables['topics'][$id]->new_text = ''; + $variables['topics'][$id]->new_url = ''; + + if ($topic->new_replies) { + $variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new post in topic %title', '@count new posts in topic %title', array('%title' => $variables['topics'][$id]->label())); + $variables['topics'][$id]->new_url = url('node/' . $topic->id(), array('query' => comment_new_page_count($topic->comment_count, $topic->new_replies, $topic, 'comment_node_forum'), 'fragment' => 'new')); + } + } + + // Build table rows from topics. + foreach ($variables['topics'] as $topic) { + $row = array(); + $row[] = array( + 'data' => array( + $topic->icon, + array( + '#markup' => '
' . $topic->title_link . '
' . $topic->submitted . '
', + ), + ), + 'class' => array('topic'), + ); + + if ($topic->moved) { + $row[] = array( + 'data' => $topic->message, + 'colspan' => '2', + ); + } + else { + $new_replies = ''; + if ($topic->new_replies) { + $new_replies = '
' . $topic->new_text . ''; + } + + $row[] = array( + 'data' => $topic->comment_count . $new_replies, + 'class' => array('replies'), + ); + $row[] = array( + 'data' => $topic->last_reply, + 'class' => array('last-reply'), + ); + } + $table['#rows'][] = $row; + } + } + $variables['topics'] = $table; + + $variables['topics_pager'] = array( + '#theme' => 'pager', ); } else { @@ -716,92 +806,6 @@ function template_preprocess_forum_list(&$variables) { } /** - * Prepares variables for forum topic list templates. - * - * Default template: forum-topic-list.html.twig. - * - * @param array $variables - * An array containing the following elements: - * - tid: Taxonomy term ID 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 = ''; - 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); - } - } - $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]->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) { - $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"); - } - else { - $variables['topics'][$id]->moved = FALSE; - $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); - - $variables['topics'][$id]->new_text = ''; - $variables['topics'][$id]->new_url = ''; - if ($topic->new_replies) { - $variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new post in topic %title', '@count new posts in topic %title', array('%title' => $variables['topics'][$id]->label())); - $variables['topics'][$id]->new_url = url('node/' . $topic->id(), array('query' => comment_new_page_count($topic->comment_count, $topic->new_replies, $topic, 'comment_node_forum'), 'fragment' => 'new')); - } - - } - } - else { - // Make this safe for the template. - $variables['topics'] = array(); - } - // Give meaning to $tid for themers. $tid actually stands for term id. - $variables['topic_id'] = $variables['tid']; - unset($variables['tid']); - - $variables['pager'] = array( - '#theme' => 'pager', - ); -} - -/** * Prepares variables for forum icon templates. * * Default template: forum-icon.html.twig. diff --git a/core/modules/forum/templates/forum-topic-list.html.twig b/core/modules/forum/templates/forum-topic-list.html.twig deleted file mode 100644 index 0e8cd16..0000000 --- a/core/modules/forum/templates/forum-topic-list.html.twig +++ /dev/null @@ -1,68 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display a list of forum topics. - * - * Available variables: - * - header: The table header. This is pre-generated with click-sorting - * information. If you need to change this, see - * template_preprocess_forum_topic_list(). - * - 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. - * - moved: A flag to indicate whether the topic has been moved to another - * forum. - * - title_link: The title of the topic. Safe to output. - * - message: If the topic has been moved, this contains an explanation and a - * link. - * - zebra: 'even' or 'odd', used for row class. - * - comment_count: The number of replies on this topic. - * - new_replies: A flag to indicate whether there are unread comments. - * - new_url: If there are unread replies, this is a link to them. - * - new_text: Text containing the translated, properly pluralized count. - * - submitted: Text representing when the topic was posted. Safe to output. - * - last_reply: Text representing when the topic was last replied to. - * - timestamp: The raw timestamp this topic was posted. - * - topic_id: Numeric ID for the current forum topic. - * - * @see template_preprocess_forum_topic_list() - * - * @ingroup themeable - */ -#} - - - {{ header }} - - - {% for topic in topics %} - - - {% if topic.moved %} - - {% else %} - - - {% endif %} - - {% endfor %} - -
- {{ topic.icon }} -
-
- {{ topic.title_link }} -
-
- {{ topic.submitted }} -
-
-
{{ topic.message }} - {{ topic.comment_count }} - {% if topic.new_replies %} -
- {{ topic.new_text }} - {% endif %} -
{{ topic.last_reply }}
-{{ pager }} diff --git a/core/modules/forum/templates/forums.html.twig b/core/modules/forum/templates/forums.html.twig index afd2490..07c1f93 100644 --- a/core/modules/forum/templates/forums.html.twig +++ b/core/modules/forum/templates/forums.html.twig @@ -19,5 +19,6 @@
{{ forums }} {{ topics }} + {{ topics_pager }}
{% endif %} diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index cabea75..d9bf980 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1336,9 +1336,6 @@ function hook_theme($existing, $type, $theme, $path) { 'forum_list' => array( 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL), ), - 'forum_topic_list' => array( - 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), - ), 'forum_icon' => array( 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0), ),