summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-01 14:22:09 (GMT)
committerAlex Pott2014-11-01 14:22:09 (GMT)
commite3e70445ca0c2aacae89dffec26d80eb392471a3 (patch)
tree4639925fd1f2e652839d1d9bfabb097388fd7e63
parent392522c083c860f3c28a7d25981cc5e3d23f70d9 (diff)
Issue #2329783 by lauriii, jamesquinton | davidhernandez: Move comment classes from preprocess to templates.
-rw-r--r--core/modules/comment/comment.module21
-rw-r--r--core/modules/comment/templates/comment.html.twig13
-rw-r--r--core/themes/bartik/templates/comment.html.twig13
3 files changed, 23 insertions, 24 deletions
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index bdf53bf..0ee6f4c 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -698,6 +698,7 @@ function template_preprocess_comment(&$variables) {
'#account' => $account,
);
$variables['author'] = drupal_render($username);
+ $variables['author_id'] = $comment->getOwnerId();
$variables['new_indicator_timestamp'] = $comment->getChangedTime();
$variables['created'] = format_date($comment->getCreatedTime());
// Avoid calling format_date() twice on the same timestamp.
@@ -790,28 +791,8 @@ function template_preprocess_comment(&$variables) {
$variables['status'] = $comment->isPublished() ? 'published' : 'unpublished';
}
- // Gather comment classes.
- $variables['attributes']['class'][] = 'comment';
- // 'published' class is not needed, it is either 'preview' or 'unpublished'.
- if ($variables['status'] != 'published') {
- $variables['attributes']['class'][] = $variables['status'];
- }
- if (!$comment->getOwnerId()) {
- $variables['attributes']['class'][] = 'by-anonymous';
- }
- else {
- // @todo Use $entity->getAuthorId() after https://drupal.org/node/2078387
- if ($commented_entity instanceof EntityOwnerInterface && $comment->getOwnerId() == $commented_entity->getOwnerId()) {
- $variables['attributes']['class'][] = 'by-' . $commented_entity->getEntityTypeId() . '-author';
- }
- }
- // Add clearfix class.
- $variables['attributes']['class'][] = 'clearfix';
-
// Add comment author user ID. Necessary for the comment-by-viewer library.
$variables['attributes']['data-comment-user-id'] = $comment->getOwnerId();
-
- $variables['content_attributes']['class'][] = 'content';
}
/**
diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig
index 801f9a6..24dbd07 100644
--- a/core/modules/comment/templates/comment.html.twig
+++ b/core/modules/comment/templates/comment.html.twig
@@ -66,7 +66,16 @@
* @ingroup themeable
*/
#}
-<article{{ attributes }}>
+{%
+ set classes = [
+ 'comment',
+ status != 'published' ? status,
+ not author_id ? 'by-anonymous',
+ author_id and author_id == commented_entity.getOwnerId() ? 'by-' ~ commented_entity.getEntityTypeId() ~ '-author',
+ 'clearfix',
+ ]
+%}
+<article{{ attributes.addClass(classes) }}>
{% if title %}
{{ title_prefix }}
{% endif %}
@@ -100,7 +109,7 @@
{{ permalink }}
</footer>
- <div{{ content_attributes }}>
+ <div{{ content_attributes.addClass('content') }}>
{{ content|without('links') }}
{% if signature %}
diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig
index c5c0a7a..0fa1991 100644
--- a/core/themes/bartik/templates/comment.html.twig
+++ b/core/themes/bartik/templates/comment.html.twig
@@ -64,7 +64,16 @@
* @see template_preprocess_comment()
*/
#}
-<article class="{{ attributes.class }} clearfix" role="article"{{ attributes|without('class', 'role') }}>
+{%
+ set classes = [
+ 'comment',
+ status != 'published' ? status,
+ not author_id ? 'by-anonymous',
+ author_id and author_id == commented_entity.getOwnerId() ? 'by-' ~ commented_entity.getEntityTypeId() ~ '-author',
+ 'clearfix',
+ ]
+%}
+<article role="article"{{ attributes.addClass(classes)|without('role') }}>
<header class="comment-header">
<div class="attribution">
@@ -110,7 +119,7 @@
{{ title_suffix }}
{% endif %}
- <div{{ content_attributes }}>
+ <div{{ content_attributes.addClass('content') }}>
{{ content|without('links') }}
</div> <!-- /.content -->