diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index e5e798f..7c52780 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -127,19 +127,22 @@ function forum_form_submit($form, &$form_state) { } /** - * Returns HTML for a forum form. + * Prepares variables for forum form templates. * - * By default this does not alter the appearance of a form at all, but is - * provided as a convenience for themers. + * Default template: forum-form.html.twig. * - * @param $variables + * @param array $variables * An associative array containing: * - form: A render element representing the form. - * - * @ingroup themeable */ -function theme_forum_form($variables) { - return drupal_render_children($variables['form']); +function template_preprocess_forum_form(&$variables) { + // Prevent recursion loop by removing '#theme' and '#theme_wrappers' keys. + // See http://drupal.org/node/1920886. + foreach (array('#theme', '#theme_wrappers') as $theme_key) { + if (isset($variables['form'][$theme_key])) { + unset($variables['form'][$theme_key]); + } + } } /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index eb2c1ec..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,23 +1089,36 @@ 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; } - // Give meaning to $tid for themers. $tid actually stands for term id. - $variables['forum_id'] = $variables['tid']; + + $variables['pager'] = array( + '#theme' => 'pager', + '#tags' => NULL, + ); + + // 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; @@ -1111,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++; @@ -1148,13 +1179,15 @@ function template_preprocess_forum_topic_list(&$variables) { $variables['topic_id'] = $variables['tid']; unset($variables['tid']); - $variables['pager'] = theme('pager'); + $variables['pager'] = array( + '#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. @@ -1162,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'); @@ -1189,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 new file mode 100644 index 0000000..614d0eb --- /dev/null +++ b/core/modules/forum/templates/forum-form.html.twig @@ -0,0 +1,20 @@ +{# +/** + * @see + * Default theme implementation 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. + * + * Available variables: + * - 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() + * + * @ingroup themeable + */ +#} +{{ form }} diff --git a/core/modules/forum/templates/forum-icon.html.twig b/core/modules/forum/templates/forum-icon.html.twig new file mode 100644 index 0000000..25d7fe6 --- /dev/null +++ b/core/modules/forum/templates/forum-icon.html.twig @@ -0,0 +1,22 @@ +{# +/** + * @file + * Default theme implementation to display an appropriate icon for a forum post. + * + * Available variables: + * - 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: Text alternative for the forum icon. + * - first_new: Indicates whether this is the first topic with new posts. + * + * @see template_preprocess() + * @see template_preprocess_forum_icon() + * + * @ingroup themeable + */ +#} +
diff --git a/core/modules/forum/templates/forum-icon.tpl.php b/core/modules/forum/templates/forum-icon.tpl.php deleted file mode 100644 index 8b70eb3..0000000 --- a/core/modules/forum/templates/forum-icon.tpl.php +++ /dev/null @@ -1,26 +0,0 @@ - - diff --git a/core/modules/forum/templates/forum-list.html.twig b/core/modules/forum/templates/forum-list.html.twig new file mode 100644 index 0000000..6e5f6da --- /dev/null +++ b/core/modules/forum/templates/forum-list.html.twig @@ -0,0 +1,84 @@ +{# +/** + * @file + * Default theme implementation to display a list of forums and containers. + * + * Available variables: + * - 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: + * - is_container: A flag indicating if the forum can contain other + * forums. Otherwise, the forum can only contain topics. + * - depth: How deep the forum is in the current hierarchy. + * - zebra: 'even' or 'odd', used for row class. + * - icon_class: 'default' or 'new', used for forum icon class. + * - icon_title: Text alternative for the forum icon. + * - name: The name of the forum. + * - link: The URL to link to this forum. + * - description: The description of this forum. + * - new_topics: A flag indicating if the forum contains unread posts. + * - new_url: A URL to the forum's unread posts. + * - new_text: Text for the above URL, which tells how many new posts. + * - old_topics: A count of posts that have already been read. + * - num_posts: The total number of posts in the forum. + * - last_reply: Text representing the last time a forum was posted or + * commented in. + * - 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 + * + * @see template_preprocess() + * @see template_preprocess_forum_list() + * + * @ingroup themeable + */ +#} +{{ '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 1..forum.depth if forum.depth > 0 %} {% endfor %}
+ {% endfor %}
+
+ {{ forum.icon_title }}
+
+
+ {% if forum.description %}
+ {{ forum.description }}
+ {% endif %}
+ {% for i in 1..forum.depth if forum.depth > 0 %} |
+ {% if forum.is_container == false %}
+
+ {{ forum.num_topics }}
+ {% if forum.new_topics == true %}
+ + {{ forum.new_text }} + {% endif %} + |
+ {{ forum.num_posts }} | +{{ forum.last_reply }} | + {% endif %} +
- | - | - | - |
---|---|---|---|
is_container ? 'colspan="4" class="container"' : 'class="forum"'; ?>>
-
- ', $forum->depth); ?>
-
- icon_title; ?>
-
-
- description): ?>
- description; ?>
-
- ', $forum->depth); ?>
- |
- is_container): ?>
-
- num_topics ?>
- new_topics): ?>
- - new_text; ?> - - |
- num_posts ?> | -last_reply ?> | - -
+ {{ topic.icon }}
+
+
+
+ {{ topic.title }}
+
+
+ {{ topic.created }}
+
+ |
+ {% if topic.moved %}
+ {{ topic.message }} | + {% else %} +
+ {{ topic.comment_count }}
+ {% if topic.new_replies %}
+ + {{ topic.new_text }} + {% endif %} + |
+ {{ topic.last_reply }} | + {% endif %} +
- icon; ?>
-
-
-
- title; ?>
-
-
- created; ?>
-
- |
- moved): ?>
- message; ?> | - -
- comment_count; ?>
- new_replies): ?>
- - new_text; ?> - - |
- last_reply; ?> | - -