diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index 7c9f6a7..8ae054d 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -127,10 +127,22 @@ function forum_form_submit($form, &$form_state) { } /** - * Preprocess variables for a forum form. + * Prepares variables for forum form templates. + * + * Default template: forum-form.html.twig. + * + * @param array $variables + * An associative array containing: + * - form: A render element representing the form. */ function template_preprocess_forum_form(&$variables) { - $variables['form'] = drupal_render_children($variables['form']); + foreach ($variables['form'] as $key => $value) { + // Prevent recursion loop by removing '#theme' and '#theme_wrappers' keys. + // See http://drupal.org/node/1920886. + if ($key == '#theme' || $key == '#theme_wrappers') { + unset($variables['form'][$key]); + } + } } /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index e2072d1..8741229 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -83,6 +83,7 @@ function forum_theme() { 'forum_form' => array( 'render element' => 'form', 'file' => 'forum.admin.inc', + 'template' => 'forum-form', ), ); } @@ -977,9 +978,11 @@ function forum_preprocess_block(&$variables) { } /** - * Preprocesses variables for forums.tpl.php. + * Prepares variables for forum templates. * - * @param $variables + * 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. @@ -993,23 +996,32 @@ function forum_preprocess_block(&$variables) { * - 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. - * - * @see forums.tpl.php */ function template_preprocess_forums(&$variables) { if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) { if (!empty($variables['forums'])) { - $variables['forums'] = theme('forum_list', $variables); + $variables['forums'] = array( + '#theme' => 'forum_list', + '#forums' => $variables['forums'], + '#parents' => $variables['parents'], + '#tid' => $variables['tid'], + ); } else { - $variables['forums'] = ''; + $variables['forums'] = array(); } if ($variables['tid'] && array_search($variables['tid'], config('forum.settings')->get('containers')) === FALSE) { - $variables['topics'] = theme('forum_topic_list', $variables); + $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'] = ''; + $variables['topics'] = array(); } // Provide separate template suggestions based on what's being output. Topic id is also accounted for. @@ -1030,24 +1042,23 @@ function template_preprocess_forums(&$variables) { } else { - $variables['forums'] = ''; - $variables['topics'] = ''; + $variables['forums'] = array(); + $variables['topics'] = array(); } } /** - * Preprocesses variables for forum-list.tpl.php. + * Prepares variables for forum list templates. + * + * Default template: forum-list.html.twig. * - * @param $variables + * @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. - * - * @see forum-list.tpl.php - * @see theme_forum_list() */ function template_preprocess_forum_list(&$variables) { global $user; @@ -1078,6 +1089,11 @@ function template_preprocess_forum_list(&$variables) { $variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics; } $variables['forums'][$id]->last_reply = theme('forum_submitted', array('topic' => $forum->last_post)); + // Cast num_posts and num_topics to strings to ensure the value can be + // printed in the template because Twig with strict variables off will not + // print int(0). + $variables['forums'][$id]->num_posts = (string) $variables['forums'][$id]->num_posts; + $variables['forums'][$id]->num_topics = (string) $variables['forums'][$id]->num_topics; } $variables['pager'] = array( @@ -1085,22 +1101,24 @@ function template_preprocess_forum_list(&$variables) { '#tags' => NULL, ); - // Give meaning to $tid for themers. $tid actually stands for term id. - $variables['forum_id'] = $variables['tid']; + // Cast forum_id to a string to ensure the value can be + // printed in the template because Twig with strict variables off will not + // print int(0). + // Give meaning to $tid for themers. $tid actually stands for term ID. + $variables['forum_id'] = (string) $variables['tid']; unset($variables['tid']); } /** - * Preprocesses variables for forum-topic-list.tpl.php. + * Prepares variables for forum topic list templates. + * + * Default template: forum-topic-list.html.twig. * - * @param $variables + * @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. - * - * @see forum-topic-list.tpl.php - * @see theme_forum_topic_list() */ function template_preprocess_forum_topic_list(&$variables) { global $forum_topic_list_header; @@ -1117,7 +1135,14 @@ function template_preprocess_forum_topic_list(&$variables) { if (!empty($variables['topics'])) { $row = 0; foreach ($variables['topics'] as $id => $topic) { - $variables['topics'][$id]->icon = theme('forum_icon', array('new_posts' => $topic->new, 'num_posts' => $topic->comment_count, 'comment_mode' => $topic->comment_mode, 'sticky' => $topic->sticky, 'first_new' => $topic->first_new)); + $variables['topics'][$id]->icon = array( + '#theme' => 'forum_icon', + '#new_posts' => $topic->new, + '#num_posts' => $topic->comment_count, + '#comment_mode' => $topic->comment_mode, + '#sticky' => $topic->sticky, + '#first_new' => $topic->first_new, + ); $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; $row++; @@ -1155,15 +1180,14 @@ function template_preprocess_forum_topic_list(&$variables) { unset($variables['tid']); $variables['pager'] = array( - '#theme' => 'pager', - '#tags' => NULL, + '#theme' => 'pager', ); } /** - * Preprocesses variables for forum-icon.tpl.php. + * Prepares variables for forum icon templates. * - * @param $variables + * @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. @@ -1171,9 +1195,6 @@ function template_preprocess_forum_topic_list(&$variables) { * or hidden. * - sticky: Indicates whether the topic is sticky. * - first_new: Indicates whether this is the first topic with new posts. - * - * @see forum-icon.tpl.php - * @see theme_forum_icon() */ function template_preprocess_forum_icon(&$variables) { $variables['hot_threshold'] = config('forum.settings')->get('topics.hot_threshold'); @@ -1198,17 +1219,16 @@ function template_preprocess_forum_icon(&$variables) { } /** - * Preprocesses variables for forum-submitted.tpl.php. + * Prepares variables for forum submission information templates. * * The submission information will be displayed in the forum list and topic * list. * - * @param $variables + * Default template: forum-submitted.html.twig. + * + * @param array $variables * An array containing the following elements: * - topic: The topic object. - * - * @see forum-submitted.tpl.php - * @see theme_forum_submitted() */ function template_preprocess_forum_submitted(&$variables) { $variables['author'] = isset($variables['topic']->uid) ? theme('username', array('account' => $variables['topic'])) : ''; diff --git a/core/modules/forum/templates/forum-form.html.twig b/core/modules/forum/templates/forum-form.html.twig index 63f13a0..614d0eb 100644 --- a/core/modules/forum/templates/forum-form.html.twig +++ b/core/modules/forum/templates/forum-form.html.twig @@ -7,7 +7,9 @@ * provided as a convenience for themers. * * Available variables: - * - form: A render element representing the form. + * - form: The complete form. Use {{ form }} to print the entire form, or print + * a subset such as {{ form.title }}. Use {% hide(form.description) %} to + * temporarily suppress the printing of a given element. * * @see template_preprocess() * @see template_preprocess_forum_form() diff --git a/core/modules/forum/templates/forum-icon.html.twig b/core/modules/forum/templates/forum-icon.html.twig index 639679f..25d7fe6 100644 --- a/core/modules/forum/templates/forum-icon.html.twig +++ b/core/modules/forum/templates/forum-icon.html.twig @@ -7,7 +7,7 @@ * - new_posts: Indicates whether or not the topic contains new posts. * - icon_class: The icon to display. May be one of 'hot', 'hot-new', 'new', * 'default', 'closed', or 'sticky'. - * - icon_title: @TODO + * - icon_title: Text alternative for the forum icon. * - first_new: Indicates whether this is the first topic with new posts. * * @see template_preprocess() @@ -16,9 +16,7 @@ * @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 46afb09..250332a 100644 --- a/core/modules/forum/templates/forum-list.html.twig +++ b/core/modules/forum/templates/forum-list.html.twig @@ -4,11 +4,11 @@ * Default theme implementation to display a list of forums and containers. * * Available variables: - * - forums: An array of forums and containers to display. It is keyed to the + * - forums: A list of forums and containers to display. It is keyed to the * numeric IDs of all child forums and containers. Each forum in forums * contains: - * - forum.is_container: TRUE if the forum can contain other forums. FALSE - * if the forum can contain only topics. + * - forum.is_container: A flag indicating if the forum can contain other + * forums. Otherwise, the forum can only contain topics. * - forum.depth: How deep the forum is in the current hierarchy. * - forum.zebra: 'even' or 'odd' string used for row class. * - forum.icon_class: 'default' or 'new' string used for forum icon class. @@ -16,7 +16,7 @@ * - forum.name: The name of the forum. * - forum.link: The URL to link to this forum. * - forum.description: The description of this forum. - * - forum.new_topics: TRUE if the forum contains unread posts. + * - forum.new_topics: A flag indicating if the forum contains unread posts. * - forum.new_url: A URL to the forum's unread posts. * - forum.new_text: Text for the above URL, which tells how many new posts. * - forum.old_topics: A count of posts that have already been read. @@ -26,7 +26,8 @@ * - forum_id: Forum ID for the current forum. Parent to all items within the * forums array. * - * @TODO Replace this with existing theme functions: http://drupal.org/node/1812684 + * @todo Replace this with existing theme functions: + * http://drupal.org/node/1812684 * * @see template_preprocess() * @see template_preprocess_forum_list() @@ -37,25 +38,26 @@ - - - - + + + + {% for child_id, forum in forums %} - {% if forum.is_container == false %} {% for topic in topics %} - - {% if topic.moved %} diff --git a/core/modules/forum/templates/forums.html.twig b/core/modules/forum/templates/forums.html.twig index 67a4539..59fff7d 100644 --- a/core/modules/forum/templates/forums.html.twig +++ b/core/modules/forum/templates/forums.html.twig @@ -17,8 +17,8 @@ */ #} {% if forums_defined %} -
- {{ forums }} - {{ topics }} -
+
+ {{ forums }} + {{ topics }} +
{% endif %}
{{ 'Forum' | t }}{{ 'Topics' | t }}{{ 'Posts' | t }}{{ 'Last post' | t }}{{ 'Forum'|t }}{{ 'Topics'|t }}{{ 'Posts'|t }}{{ 'Last post'|t }}
- {# /* Enclose the contents of this cell with X divs, where X is the - * depth this forum resides at. This will allow us to use CSS - * left-margin for indenting. - */ #} - {% for i in 0..forum.depth %}
{% endfor %} + {%- endif -%}> + {# + Enclose the contents of this cell with X divs, where X is the + depth this forum resides at. This will allow us to use CSS + left-margin for indenting. + #} + {% for i in 1..forum.depth if forum.depth > 0 %}
{% endfor %}
{{ forum.icon_title }}
@@ -63,7 +65,7 @@ {% if forum.description %}
{{ forum.description }}
{% endif %} - {% for i in 0..forum.depth %}
{% endfor %} + {% for i in 1..forum.depth if forum.depth > 0 %}
{% endfor %}
diff --git a/core/modules/forum/templates/forum-submitted.html.twig b/core/modules/forum/templates/forum-submitted.html.twig index 91c139d..ad059dc 100644 --- a/core/modules/forum/templates/forum-submitted.html.twig +++ b/core/modules/forum/templates/forum-submitted.html.twig @@ -1,7 +1,7 @@ {# /** * @file - * Default theme implementation formats a forum post submission string. + * Default theme implementation for a forum post submission string. * * The submission string indicates when and by whom a topic was submitted. * @@ -18,7 +18,7 @@ */ #} {% if time %} - + {% else %} - {{ 'n/a' | t }} + {{ '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 f81ca70..ae2e224 100644 --- a/core/modules/forum/templates/forum-topic-list.html.twig +++ b/core/modules/forum/templates/forum-topic-list.html.twig @@ -8,8 +8,7 @@ * information. If you need to change this, see * template_preprocess_forum_topic_list(). * - pager: The pager to display beneath the table. - * - topics: An array of topics to be displayed. Each $topic in $topics - * contains: + * - topics: An array of topics to be displayed. Each topic in topics contains: * - topic.icon: The icon to display. * - topic.moved: A flag to indicate whether the topic has been moved to * another forum. @@ -43,13 +42,15 @@
{{ topic.icon }} -
- {{ topic.title }} -
-
- {{ topic.created }} +
+ {{ topic.icon }} +
+
+ {{ topic.title }} +
+
+ {{ topic.created }} +