Commit 125424bc authored by alexpott's avatar alexpott

Issue #2405675 by larowlan: Comment field settings don't save

parent 0d868a80
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\CommentType;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Session\AnonymousUserSession;
...@@ -106,21 +107,13 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { ...@@ -106,21 +107,13 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$anonymous_user = new AnonymousUserSession(); $anonymous_user = new AnonymousUserSession();
$element['comment'] = array( $element['default_mode'] = array(
'#type' => 'details',
'#title' => t('Comment form settings'),
'#open' => TRUE,
'#attached' => array(
'library' => array('comment/drupal.comment'),
),
);
$element['comment']['default_mode'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Threading'), '#title' => t('Threading'),
'#default_value' => $settings['default_mode'], '#default_value' => $settings['default_mode'],
'#description' => t('Show comment replies in a threaded list.'), '#description' => t('Show comment replies in a threaded list.'),
); );
$element['comment']['per_page'] = array( $element['per_page'] = array(
'#type' => 'number', '#type' => 'number',
'#title' => t('Comments per page'), '#title' => t('Comments per page'),
'#default_value' => $settings['per_page'], '#default_value' => $settings['per_page'],
...@@ -129,7 +122,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { ...@@ -129,7 +122,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
'#max' => 1000, '#max' => 1000,
'#step' => 10, '#step' => 10,
); );
$element['comment']['anonymous'] = array( $element['anonymous'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Anonymous commenting'), '#title' => t('Anonymous commenting'),
'#default_value' => $settings['anonymous'], '#default_value' => $settings['anonymous'],
...@@ -140,12 +133,12 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { ...@@ -140,12 +133,12 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
), ),
'#access' => $anonymous_user->hasPermission('post comments'), '#access' => $anonymous_user->hasPermission('post comments'),
); );
$element['comment']['form_location'] = array( $element['form_location'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Show reply form on the same page as comments'), '#title' => t('Show reply form on the same page as comments'),
'#default_value' => $settings['form_location'], '#default_value' => $settings['form_location'],
); );
$element['comment']['preview'] = array( $element['preview'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Preview comment'), '#title' => t('Preview comment'),
'#default_value' => $settings['preview'], '#default_value' => $settings['preview'],
......
...@@ -360,12 +360,16 @@ function testCommentFunctionality() { ...@@ -360,12 +360,16 @@ function testCommentFunctionality() {
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1'); $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1');
$this->assertFieldChecked('edit-default-value-input-comment-0-status-2'); $this->assertFieldChecked('edit-default-value-input-comment-0-status-2');
// Test comment option change in field settings. // Test comment option change in field settings.
$edit = array('default_value_input[comment][0][status]' => CommentItemInterface::CLOSED); $edit = array(
'default_value_input[comment][0][status]' => CommentItemInterface::CLOSED,
'field[settings][anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT,
);
$this->drupalPostForm(NULL, $edit, t('Save settings')); $this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment'); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0'); $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
$this->assertFieldChecked('edit-default-value-input-comment-0-status-1'); $this->assertFieldChecked('edit-default-value-input-comment-0-status-1');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2'); $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
$this->assertFieldByName('field[settings][anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
// Add a new comment-type. // Add a new comment-type.
$bundle = CommentType::create(array( $bundle = CommentType::create(array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment