commit c51f8de814582ee390a97e0e1e858da25831565e Author: Joel Pittet Date: Sun Jan 12 23:01:01 2014 -0800 remove extra loop, set default arrays, stop printing empty table tags diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 049c822..ba3df11 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -73,7 +73,7 @@ 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), + 'variables' => array('forums' => array(), 'topics' => array(), 'topics_pager' => array(), 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), ), 'forum_list' => array( 'template' => 'forum-list', @@ -621,7 +621,6 @@ 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'])) { @@ -632,15 +631,13 @@ function template_preprocess_forums(&$variables) { '#tid' => $variables['tid'], ); } - else { - $variables['forums'] = array(); - } - if ($variables['term'] && empty($variables['term']->forum_container->value)) { + if ($variables['term'] && empty($variables['term']->forum_container->value) && !empty($variables['topics'])) { global $forum_topic_list_header; $table = array( '#theme' => 'table__forum_topic_list', + '#responsive' => FALSE, '#attributes' => array('id' => 'forum-topic-' . $variables['tid']), '#header' => array(), '#rows' => array(), @@ -650,101 +647,90 @@ function template_preprocess_forums(&$variables) { $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, - ); + 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); + // 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 = ''; + $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')); - } + 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 . '
', - ), + $row = array(); + $row[] = array( + 'data' => array( + $topic->icon, + array( + '#markup' => '
' . $topic->title_link . '
' . $topic->submitted . '
', ), - 'class' => array('topic'), - ); + ), + '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'), - ); + if ($topic->moved) { + $row[] = array( + 'data' => $topic->message, + 'colspan' => '2', + ); + } + else { + $new_replies = ''; + if ($topic->new_replies) { + $new_replies = '
' . $topic->new_text . ''; } - $table['#rows'][] = $row; + + $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'] = $table; $variables['topics_pager'] = array( '#theme' => 'pager', ); } - else { - $variables['topics'] = array(); - } - } - else { - $variables['forums'] = array(); - $variables['topics'] = array(); } } diff --git a/core/modules/forum/templates/forums.html.twig b/core/modules/forum/templates/forums.html.twig index 07c1f93..11bc8e4 100644 --- a/core/modules/forum/templates/forums.html.twig +++ b/core/modules/forum/templates/forums.html.twig @@ -7,7 +7,7 @@ * * 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). + * - topics: The topics to display. * - forums_defined: A flag to indicate that the forums are configured. * * @see template_preprocess_forums()