diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e353501..b197116 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -157,9 +157,8 @@ function comment_theme() { 'render element' => 'elements', 'template' => 'comment', ), - 'comment_wrapper' => array( - 'render element' => 'content', - 'template' => 'comment-wrapper', + 'field__comment' => array( + 'template' => 'field--comment', ), ); } @@ -1424,31 +1423,33 @@ function template_preprocess_comment(&$variables) { } /** - * Prepares variables for comment wrapper templates. + * Prepares variables for comment field templates. * - * Default template: comment-wrapper.html.twig. + * Default template: field__comment.html.twig. * * @param array $variables * An associative array containing: - * - content: An associative array containing render arrays for the list of + * - element: 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) { +function template_preprocess_field__comment(&$variables) { // Provide contextual information. - $variables['entity'] = $variables['content']['#entity']; - $variables['display_mode'] = $variables['content']['#display_mode']; + $variables['entity'] = $variables['element'][0]['#entity']; + $variables['display_mode'] =$variables['element'][0]['#display_mode']; - // The comment form is optional and may not exist. - $variables['content'] += array('comment_form' => array()); - - $variables['attributes']['id'] = 'comments'; + // Use field title for field label. + $variables['label'] = $variables['element']['#title']; // 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']; + $variables['comments'] = $variables['element'][0]['comments']; + // The comment form is optional and may not exist. + $variables['comment_form'] = array(); + if (!empty($variables['element'][0]['comment_form'])) { + $variables['comment_form'] = $variables['element'][0]['comment_form']; + } } /** diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 1832e32..c774648 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -176,7 +176,7 @@ public function viewElements(FieldItemListInterface $items) { } $elements[] = $output + array( - '#theme' => 'comment_wrapper__' . $entity->getEntityTypeId() . '__' . $entity->bundle() . '__' . $field_name, + '#theme' => 'field__comment', '#entity' => $entity, '#display_mode' => $this->getFieldSetting('default_mode'), 'comments' => array(), diff --git a/core/modules/comment/templates/comment-wrapper.html.twig b/core/modules/comment/templates/comment-wrapper.html.twig deleted file mode 100644 index b19c051..0000000 --- a/core/modules/comment/templates/comment-wrapper.html.twig +++ /dev/null @@ -1,52 +0,0 @@ -{# -/** - * @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. - * - entity: The 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') %} - *

{{ 'These comments are displayed in a threaded list.'|t }}

- * {% endif %} - * @endcode - * - COMMENT_MODE_FLAT - * - COMMENT_MODE_THREADED - * - * @see template_preprocess_comment_wrapper() - * - * @ingroup themeable - */ -#} - - {% if comments and (entity.entityType != 'node' or entity.bundle != 'forum') %} - {{ title_prefix }} -

{{ 'Comments'|t }}

- {{ title_suffix }} - {% endif %} - - {{ comments }} - - {% if form %} -

{{ 'Add new comment'|t }}

- {{ form }} - {% endif %} - - diff --git a/core/modules/comment/templates/field--comment.html.twig b/core/modules/comment/templates/field--comment.html.twig new file mode 100644 index 0000000..e4959bd --- /dev/null +++ b/core/modules/comment/templates/field--comment.html.twig @@ -0,0 +1,31 @@ +{# +/** + * @file + * Defult theme override for comment fields. + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - label_hidden: Whether the field label has been set to hidden. + * - label_attributes: HTML attributes for the label. + * - label: The label for the field. + * - content_attributes: HTML attributes for the content. + * - items: List of all the field items. + * - item_attributes: HTML attributes for each item. + * + * @see template_preprocess_field() + * @see bartik_preprocess_field() + */ +#} + + {% if not label_hidden %} +

{{ label }}

+ {% endif %} + + {{ comments }} + + {% if comment_form %} +

{% trans %}Add new comment{% endtrans %}

+ {{ comment_form }} + {% endif %} + +