Commit 49f4fddb authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1962846 by andypost, Wim Leers, InternetDevels: Use field instance name...

Issue #1962846 by andypost, Wim Leers, InternetDevels: Use field instance name for header of comment list, drop comment-wrapper template.
parent 67c051d4
Loading
Loading
Loading
Loading
+23 −17
Changes for core/modules/comment/comment.module: 23 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -134,9 +134,9 @@ function comment_theme() {
      'render element' => 'elements',
      'template' => 'comment',
    ),
    'comment_wrapper' => array(
      'render element' => 'content',
      'template' => 'comment-wrapper',
    'field__comment' => array(
      'base hook' => 'field',
      'template' => 'field--comment',
    ),
  );
}
@@ -988,31 +988,37 @@ 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.
 *
 * @todo Rename to template_preprocess_field__comment() once
 *   https://www.drupal.org/node/939462 is resolved.
 */
function template_preprocess_comment_wrapper(&$variables) {
function comment_preprocess_field(&$variables) {
  $element = $variables['element'];
  if ($element['#field_type'] == 'comment') {
    // Provide contextual information.
  $variables['entity'] = $variables['content']['#entity'];
  $variables['display_mode'] = $variables['content']['#display_mode'];

  // The comment form is optional and may not exist.
  $variables['content'] += array('comment_form' => array());

  $variables['attributes']['id'] = 'comments';
    $variables['comment_display_mode'] = $element[0]['#comment_display_mode'];
    $variables['comment_type'] = $element[0]['#comment_type'];

  // Add a comment wrapper class.
    // Adjust a comment field's attributes.
    $variables['attributes']['class'][] = 'comment-wrapper';
    $variables['title_attributes']['class'][] = 'title';

    // Append additional attributes (eg. RDFa) from the first field item.
    $variables['attributes'] += $variables['item_attributes'][0]->storage();

    // Create separate variables for the comments and comment form.
  $variables['comments'] = $variables['content']['comments'];
  $variables['form'] = $variables['content']['comment_form'];
    $variables['comments'] = $element[0]['comments'];
    $variables['comment_form'] = $element[0]['comment_form'];
    $variables['content_attributes']['class'] = array('title', 'comment-form__title');
  }
}

/**
+2 −2
Changes for core/modules/comment/src/CommentManager.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment',
    // Make sure the instance doesn't already exist.
    if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
      $instance = $this->entityManager->getStorage('field_instance_config')->create(array(
        'label' => 'Comment settings',
        'label' => 'Comments',
        'description' => '',
        'field_name' => $field_name,
        'entity_type' => $entity_type,
@@ -212,7 +212,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment',
      // Set default to display comment list.
      entity_get_display($entity_type, $bundle, 'default')
        ->setComponent($field_name, array(
          'label' => 'hidden',
          'label' => 'above',
          'type' => 'comment_default',
          'weight' => 20,
        ))
+2 −3
Changes for core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -219,9 +219,8 @@ public function viewElements(FieldItemListInterface $items) {
      }

      $elements[] = $output + array(
        '#theme' => 'comment_wrapper__' . $entity->getEntityTypeId() . '__' . $entity->bundle() . '__' . $field_name,
        '#entity' => $entity,
        '#display_mode' => $this->getFieldSetting('default_mode'),
        '#comment_type' => $this->getFieldSetting('comment_type'),
        '#comment_display_mode' => $this->getFieldSetting('default_mode'),
        'comments' => array(),
        'comment_form' => array(),
      );
+3
Changes for core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
      // Get default value from the field instance.
      $field_default_values = $this->fieldDefinition->getDefaultValue($entity);

      // Override widget title to be helpful for end users.
      $element['#title'] = $this->t('Comment settings');

      $element += array(
        '#type' => 'details',
        // Open the details when the selected value is different to the stored
+1 −1
Changes for core/modules/comment/src/Tests/CommentNonNodeTest.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ function testCommentFunctionality() {
    $this->drupalLogin($limited_user);
    // Test that default field exists.
    $this->drupalGet('entity_test/structure/entity_test/fields');
    $this->assertText(t('Comment settings'));
    $this->assertText(t('Comments'));
    $this->assertLinkByHref('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
    // Test widget hidden option is not visible when there's no comments.
    $this->drupalGet('entity_test/structure/entity_test/entity-test/fields/entity_test.entity_test.comment');
Loading