summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-24 17:04:14 (GMT)
committerAlex Pott2013-05-24 17:04:14 (GMT)
commit5f9bee77071027a4fee1544a5e66773a30f7a74b (patch)
tree163d9196de2bdfbbea121dbba902dcb1b888ee82
parent67b166ca27f110ef2724b6cf5a00d49a10375323 (diff)
Issue #1898054 by pixelmord, jenlampton, steveoliver, EVIIILJ, c4rl, vlad.dancer, Fabianx, joelpittet, jwilson3, thedavidmeister, shanethehat, Cottser: Convert comment module to Twig.
-rw-r--r--core/modules/comment/comment.api.php3
-rw-r--r--core/modules/comment/comment.module32
-rw-r--r--core/modules/comment/templates/comment-wrapper.html.twig53
-rw-r--r--core/modules/comment/templates/comment-wrapper.tpl.php48
-rw-r--r--core/modules/comment/templates/comment.html.twig106
-rw-r--r--core/modules/comment/templates/comment.tpl.php110
-rw-r--r--core/modules/rdf/rdf.module4
7 files changed, 190 insertions, 166 deletions
diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php
index 793d9ad..a27899e 100644
--- a/core/modules/comment/comment.api.php
+++ b/core/modules/comment/comment.api.php
@@ -113,8 +113,7 @@ function hook_comment_view(\Drupal\comment\Plugin\Core\Entity\Comment $comment,
* If the module wishes to act on the rendered HTML of the comment rather than
* the structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_HOOK() for
- * comment.tpl.php. See drupal_render() and theme() documentation respectively
- * for details.
+ * comment.html.twig. See drupal_render() documentation for details.
*
* @param $build
* A renderable array representing the comment.
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 0c2cd55..807b672 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1553,9 +1553,14 @@ function comment_prepare_author(Comment $comment) {
}
/**
- * Preprocesses variables for comment.tpl.php.
+ * Prepares variables for comment templates.
*
- * @see comment.tpl.php
+ * Default template: comment.html.twig.
+ *
+ * @param array $variables
+ * An associative array containing:
+ * - elements: An associative array containing the comment and node objects.
+ * Array keys: #comment, #node.
*/
function template_preprocess_comment(&$variables) {
$comment = $variables['elements']['#comment'];
@@ -1564,6 +1569,7 @@ function template_preprocess_comment(&$variables) {
$variables['node'] = $node;
$account = comment_prepare_author($comment);
+ // @todo Do not call theme() here. We do this for purposes of t().
$variables['author'] = theme('username', array('account' => $account));
$variables['new'] = $comment->new->value ? t('new') : '';
$variables['created'] = format_date($comment->created->value);
@@ -1583,6 +1589,7 @@ function template_preprocess_comment(&$variables) {
else {
$variables['user_picture'] = array();
}
+
if (config('user.settings')->get('signatures') && !empty($account->signature)) {
$variables['signature'] = check_markup($account->signature, $account->signature_format, '', TRUE) ;
}
@@ -1602,6 +1609,7 @@ function template_preprocess_comment(&$variables) {
$comment_parent = $comment->pid->entity;
$account_parent = comment_prepare_author($comment_parent);
$variables['parent_comment'] = $comment_parent;
+ // @todo Do not call theme() here. We do this for purposes of t().
$variables['parent_author'] = theme('username', array('account' => $account_parent));
$variables['parent_created'] = format_date($comment_parent->created->value);
// Avoid calling format_date() twice on the same timestamp.
@@ -1664,6 +1672,10 @@ function template_preprocess_comment(&$variables) {
$variables['attributes']['class'][] = 'by-viewer';
}
}
+ // Add clearfix class.
+ $variables['attributes']['class'][] = 'clearfix';
+
+ $variables['content_attributes']['class'][] = 'content';
}
/**
@@ -1714,19 +1726,31 @@ function theme_comment_post_forbidden($variables) {
}
/**
- * Preprocesses variables for comment-wrapper.tpl.php.
+ * Prepares variables for comment wrapper templates.
+ *
+ * Default template: comment-wrapper.html.twig.
*
- * @see comment-wrapper.tpl.php
+ * @param array $variables
+ * An associative array containing:
+ * - content: An associative array containing render arrays for the list of
+ * comments, and the comment form. Array keys: comments, comment_form.
*/
function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information.
$variables['node'] = $variables['content']['#node'];
$variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
+
// The comment form is optional and may not exist.
$variables['content'] += array('comment_form' => array());
+ $variables['attributes']['id'] = 'comments';
+
// Add a comment wrapper class.
$variables['attributes']['class'][] = 'comment-wrapper';
+
+ // Create separate variables for the comments and comment form.
+ $variables['comments'] = $variables['content']['comments'];
+ $variables['form'] = $variables['content']['comment_form'];
}
/**
diff --git a/core/modules/comment/templates/comment-wrapper.html.twig b/core/modules/comment/templates/comment-wrapper.html.twig
new file mode 100644
index 0000000..dbf37cd
--- /dev/null
+++ b/core/modules/comment/templates/comment-wrapper.html.twig
@@ -0,0 +1,53 @@
+{#
+/**
+ * @file
+ * Default theme implementation for a comments container.
+ *
+ * Available variables:
+ * - comments: List of comments rendered through comment.html.twig.
+ * - form: The 'Add new comment' form.
+ * - content: The content-related elements for the comment display. Use
+ * 'content' to print them all, or print a subset such as
+ * 'content.comment_form'.
+ * - attributes: Remaining HTML attributes for the containing element.
+ * It includes the 'class' information, which includes:
+ * - comment-wrapper: The current template type, i.e., "theming hook".
+ * - title_prefix: Additional output populated by modules, intended to be
+ * displayed in front of the main title tag that appears in the template.
+ * - title_suffix: Additional title output populated by modules, intended to
+ * be displayed after the main title tag that appears in the template.
+ *
+ * The following variables are provided for contextual information.
+ * - node: The node entity to which the comments belong.
+ * - display_mode: The display mode for the comment listing, flat or threaded.
+ * The constants below show the possible values and should be used for
+ * comparison, as in the following example:
+ * @code
+ * {% if display_mode is constant('COMMENT_MODE_THREADED') %}
+ * <h3>{{ 'These comments are displayed in a threaded list.'|t }}</h3>
+ * {% endif %}
+ * @endcode
+ * - COMMENT_MODE_FLAT
+ * - COMMENT_MODE_THREADED
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_comment_wrapper()
+ *
+ * @ingroup themeable
+ */
+#}
+<section{{ attributes }}>
+ {% if comments and node.type != 'forum' %}
+ {{ title_prefix }}
+ <h2 class="title">{{ 'Comments'|t }}</h2>
+ {{ title_suffix }}
+ {% endif %}
+
+ {{ comments }}
+
+ {% if form %}
+ <h2 class="title comment-form">{{ 'Add new comment'|t }}</h2>
+ {{ form }}
+ {% endif %}
+
+</section>
diff --git a/core/modules/comment/templates/comment-wrapper.tpl.php b/core/modules/comment/templates/comment-wrapper.tpl.php
deleted file mode 100644
index ac1c27f..0000000
--- a/core/modules/comment/templates/comment-wrapper.tpl.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-/**
- * @file
- * Provides an HTML container for comments.
- *
- * Available variables:
- * - $content: The array of content-related elements for the node. Use
- * render($content) to print them all, or
- * print a subset such as render($content['comment_form']).
- * - $attributes: An instance of Attributes class that can be manipulated as an
- * array and printed as a string.
- * It includes the 'class' information, which includes:
- * - comment-wrapper: The current template type, i.e., "theming hook".
- * - $title_prefix (array): An array containing additional output populated by
- * modules, intended to be displayed in front of the main title tag that
- * appears in the template.
- * - $title_suffix (array): An array containing additional output populated by
- * modules, intended to be displayed after the main title tag that appears in
- * the template.
- *
- * The following variables are provided for contextual information.
- * - $node: Node entity the comments are attached to.
- * The constants below the variables show the possible values and should be
- * used for comparison.
- * - $display_mode
- * - COMMENT_MODE_FLAT
- * - COMMENT_MODE_THREADED
- *
- * @see template_preprocess_comment_wrapper()
- *
- * @ingroup themeable
- */
-?>
-<section id="comments" <?php print $attributes; ?>>
- <?php if ($content['comments'] && $node->type != 'forum'): ?>
- <?php print render($title_prefix); ?>
- <h2 class="title"><?php print t('Comments'); ?></h2>
- <?php print render($title_suffix); ?>
- <?php endif; ?>
-
- <?php print render($content['comments']); ?>
-
- <?php if ($content['comment_form']): ?>
- <h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
- <?php print render($content['comment_form']); ?>
- <?php endif; ?>
-</section>
diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig
new file mode 100644
index 0000000..4b441dd
--- /dev/null
+++ b/core/modules/comment/templates/comment.html.twig
@@ -0,0 +1,106 @@
+{#
+/**
+ * @file
+ * Default theme implementation for comments.
+ *
+ * Available variables:
+ * - author: Comment author. Can be a link or plain text.
+ * - content: The content-related items for the comment display. Use
+ * {{ content }} to print them all, or print a subset such as
+ * {{ content.field_example }}. Use hide(content.field_example) to temporarily
+ * suppress the printing of a given element.
+ * - created: Formatted date and time for when the comment was created.
+ * Preprocess functions can reformat it by calling format_date() with the
+ * desired parameters on the 'comment.created' variable.
+ * - changed: Formatted date and time for when the comment was last changed.
+ * Preprocess functions can reformat it by calling format_date() with the
+ * desired parameters on the 'comment.changed' variable.
+ * - new: New comment marker.
+ * - permalink: Comment permalink.
+ * - submitted: Submission information created from author and created
+ * during template_preprocess_comment().
+ * - user_picture: The comment author's profile picture.
+ * - signature: The comment author's signature.
+ * - status: Comment status. Possible values are:
+ * unpublished, published, or preview.
+ * - title: Comment title, linked to the comment.
+ * - attributes.class: List of classes that can be used to style contextually
+ * through CSS. The default values can be one or more of the following:
+ * - comment: The current template type; e.g., 'theming hook'.
+ * - by-anonymous: Comment by an unregistered user.
+ * - by-node-author: Comment by the author of the parent node.
+ * - preview: When previewing a new or edited comment.
+ * The following applies only to viewers who are registered users:
+ * - unpublished: An unpublished comment visible only to administrators.
+ * - by-viewer: Comment by the user currently viewing the page.
+ * - new: New comment since the last visit.
+ * - title_prefix: Additional output populated by modules, intended to be
+ * displayed in front of the main title tag that appears in the template.
+ * - title_suffix: Additional output populated by modules, intended to be
+ * displayed after the main title tag that appears in the template.
+ * - content_attributes: List of classes for the styling of the comment content.
+ *
+ * These variables are provided to give context about the parent comment (if
+ * any):
+ * - comment_parent: Full parent comment entity (if any).
+ * - parent_author: Equivalent to author for the parent comment.
+ * - parent_created: Equivalent to created for the parent comment.
+ * - parent_changed: Equivalent to changed for the parent comment.
+ * - parent_title: Equivalent to title for the parent comment.
+ * - parent_permalink: Equivalent to permalink for the parent comment.
+ * - parent: A text string of parent comment submission information created from
+ * 'parent_author' and 'parent_created' during template_preprocess_comment().
+ * This information is presented to help screen readers follow lengthy
+ * discussion threads. You can hide this from sighted users using the class
+ * element-invisible.
+ *
+ * These two variables are provided for context:
+ * - comment: Full comment object.
+ * - node: Node entity the comments are attached to.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_comment()
+ *
+ * @ingroup themeable
+ */
+#}
+<article{{ attributes }}>
+ {{ title_prefix }}
+
+ {% if new %}
+ <mark class="new">{{ new }}</mark>
+ {% endif %}
+
+ <h3{{ title_attributes }}>{{ title }}</h3>
+
+ {{ title_suffix }}
+
+ <footer>
+ {{ user_picture }}
+ <p class="submitted">{{ submitted }}</p>
+
+ {#
+ Indicate the semantic relationship between parent and child comments
+ for accessibility. The list is difficult to navigate in a screen
+ reader without this information.
+ #}
+ {% if parent %}
+ <p class="parent element-invisible">{{ parent }}</p>
+ {% endif %}
+
+ {{ permalink }}
+ </footer>
+
+ <div{{ content_attributes }}>
+ {# We hide the links now so that we can render them later. #}
+ {% hide(content.links) %}
+ {{ content }}
+
+ {% if signature %}
+ <div class="user-signature">
+ {{ signature }}
+ </div>
+ {% endif %}
+ </div>
+ {{ content.links }}
+</article>
diff --git a/core/modules/comment/templates/comment.tpl.php b/core/modules/comment/templates/comment.tpl.php
deleted file mode 100644
index 5a8a37e..0000000
--- a/core/modules/comment/templates/comment.tpl.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-/**
- * @file
- * Default theme implementation for comments.
- *
- * Available variables:
- * - $author: Comment author. Can be link or plain text.
- * - $content: An array of comment items. Use render($content) to print them
- * all, or print a subset such as render($content['field_example']). Use
- * hide($content['field_example']) to temporarily suppress the printing of a
- * given element.
- * - $created: Formatted date and time for when the comment was created.
- * Preprocess functions can reformat it by calling format_date() with the
- * desired parameters on the $comment->created variable.
- * - $changed: Formatted date and time for when the comment was last changed.
- * Preprocess functions can reformat it by calling format_date() with the
- * desired parameters on the $comment->changed variable.
- * - $new: New comment marker.
- * - $permalink: Comment permalink.
- * - $submitted: Submission information created from $author and $created during
- * template_preprocess_comment().
- * - $user_picture: The comment author's picture. Use render($user_picture) to
- * print it.
- * - $signature: Authors signature.
- * - $status: Comment status. Possible values are:
- * unpublished, published, or preview.
- * - $title: Linked title.
- * - $attributes: An instance of Attributes class that can be manipulated as an
- * array and printed as a string.
- * It includes the 'class' information, which includes:
- * - comment: The current template type; e.g., 'theming hook'.
- * - by-anonymous: Comment by an unregistered user.
- * - by-node-author: Comment by the author of the parent node.
- * - preview: When previewing a new or edited comment.
- * The following applies only to viewers who are registered users:
- * - unpublished: An unpublished comment visible only to administrators.
- * - by-viewer: Comment by the user currently viewing the page.
- * - new: New comment since the last visit.
- * - $title_prefix (array): An array containing additional output populated by
- * modules, intended to be displayed in front of the main title tag that
- * appears in the template.
- * - $title_suffix (array): An array containing additional output populated by
- * modules, intended to be displayed after the main title tag that appears in
- * the template.
- *
- * These variables are provided to give context about the parent comment (if
- * any):
- * - $comment_parent: Full parent comment object (if any).
- * - $parent_author: Equivalent to $author for the parent comment.
- * - $parent_created: Equivalent to $created for the parent comment.
- * - $parent_changed: Equivalent to $changed for the parent comment.
- * - $parent_title: Equivalent to $title for the parent comment.
- * - $parent_permalink: Equivalent to $permalink for the parent comment.
- * - $parent: A text string of parent comment submission information created
- * from $parent_author and $parent_created during
- * template_preprocess_comment(). This information is presented to help
- * screen readers follow lengthy discussion threads. You can hide this from
- * sighted users using the class element-invisible.
- *
- * These two variables are provided for context:
- * - $comment: Full comment object.
- * - $node: Node entity the comments are attached to.
- *
- * @see template_preprocess()
- * @see template_preprocess_comment()
- * @see template_process()
- * @see theme_comment()
- *
- * @ingroup themeable
- */
-?>
-<article class="<?php print $attributes['class']; ?> clearfix"<?php print $attributes; ?>>
-
- <?php print render($title_prefix); ?>
- <?php if ($new): ?>
- <mark class="new"><?php print $new; ?></mark>
- <?php endif; ?>
- <h3<?php print $title_attributes; ?>><?php print $title; ?></h3>
- <?php print render($title_suffix); ?>
-
- <footer>
- <?php print render($user_picture); ?>
- <p class="submitted"><?php print $submitted; ?></p>
- <?php
- // Indicate the semantic relationship between parent and child comments
- // for accessibility. The list is difficult to navigate in a screen
- // reader without this information.
- if ($parent):
- ?>
- <p class="parent element-invisible"><?php print $parent; ?></p>
- <?php endif; ?>
- <?php print $permalink; ?>
- </footer>
-
- <div class="content"<?php print $content_attributes; ?>>
- <?php
- // We hide the links now so that we can render them later.
- hide($content['links']);
- print render($content);
- ?>
- <?php if ($signature): ?>
- <div class="user-signature">
- <?php print $signature; ?>
- </div>
- <?php endif; ?>
- </div>
-
- <?php print render($content['links']) ?>
-</article>
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index a2f74a3..3783f6b 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -701,7 +701,7 @@ function rdf_preprocess_username(&$variables) {
}
/**
- * Implements hook_preprocess_HOOK() for comment.tpl.php.
+ * Implements hook_preprocess_HOOK() for comment.html.twig.
*/
function rdf_preprocess_comment(&$variables) {
$comment = $variables['comment'];
@@ -848,7 +848,7 @@ function rdf_preprocess_image(&$variables) {
* - variable_name: The name of the variable by which the template will
* refer to this content. Each template file has documentation about
* the variables it uses. For example, if this function is called in
- * preparing the $author variable for comment.tpl.php, then the
+ * preparing the $author variable for comment.html.twig, then the
* 'variable_name' is 'author'.
* - variables: The full array of variables about to be passed to the
* template.