Commit f6800535 authored by catch's avatar catch
Browse files

Issue #3373938 by lauriii, keshav.k: Comment settings are confusing

parent 9028e6c0
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
      '#title' => $this->t('Comments'),
      '#title_display' => 'invisible',
      '#default_value' => $items->status,
      '#required ' => TRUE,
      '#options' => [
        CommentItemInterface::OPEN => $this->t('Open'),
        CommentItemInterface::CLOSED => $this->t('Closed'),
@@ -44,22 +45,18 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
        '#description' => $this->t('Users cannot post comments, but existing comments will be displayed.'),
      ],
      CommentItemInterface::HIDDEN => [
        '#description' => $this->t('Comments are hidden from view.'),
        '#description' => $this->t('Comments and the comment form are hidden from view.'),
      ],
    ];

    // Setting a value in the default value widget is required.
    if ($this->isDefaultValueWidget($form_state)) {
      $element['status']['#required'] = TRUE;
    }

    // If the entity doesn't have any comments, the "hidden" option makes no
    // If the entity doesn't have any comments, the "Closed" option makes no
    // sense, so don't even bother presenting it to the user unless this is the
    // default value widget on the field settings form.
    if (!$this->isDefaultValueWidget($form_state) && !$items->comment_count) {
      $element['status'][CommentItemInterface::HIDDEN]['#access'] = FALSE;
      // Also adjust the description of the "closed" option.
      $element['status'][CommentItemInterface::CLOSED]['#description'] = $this->t('Users cannot post comments.');
      // Only hide the option when it's not the currently selected option.
      if ($element['status']['#default_value'] !== CommentItemInterface::CLOSED) {
        $element['status'][CommentItemInterface::CLOSED]['#access'] = FALSE;
      }
    }
    // If the advanced settings tabs-set is available (normally rendered in the
    // second column on wide-resolutions), place the field as a details element
+3 −2
Original line number Diff line number Diff line
@@ -458,9 +458,9 @@ public function testCommentFunctionality() {
    $new_entity = EntityTest::create($data);
    $new_entity->save();
    $this->drupalGet('entity_test/manage/' . $new_entity->id() . '/edit');
    $this->assertSession()->checkboxNotChecked('edit-field-foobar-0-status-1');
    $this->assertSession()->checkboxChecked('edit-field-foobar-0-status-2');
    $this->assertSession()->fieldNotExists('edit-field-foobar-0-status-0');
    $this->assertSession()->checkboxNotChecked('edit-field-foobar-0-status-0');
    $this->assertSession()->fieldNotExists('edit-field-foobar-0-status-1');

    // @todo Check proper URL and form https://www.drupal.org/node/2458323
    $this->drupalGet('comment/reply/entity_test/comment/' . $new_entity->id());
@@ -544,6 +544,7 @@ public function testCommentSettingsNotRequired() {
    // with the default value.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('/entity_test/add');
    $this->assertSession()->checkboxChecked('edit-comment-0-status-0');
    $edit = [
      "name[0][value]" => 'Comment test',
    ];