From a1529fe90fa9a7abf9901d09235f99c88ccfb410 Mon Sep 17 00:00:00 2001 From: xjm Date: Thu, 23 Jun 2016 12:32:50 +0200 Subject: [PATCH] Issue #2361469 by mikeker, Shreya Shetty, pjonckiere, Andres Mejia, geffio, jhedstrom, yoroy, swentel, R. Volk: Single on/off checkboxes should "Use field label" by default --- .../FieldWidget/BooleanCheckboxWidget.php | 2 +- .../src/Tests/Boolean/BooleanFieldTest.php | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php index 9a3e6f7d282..3106fbe6b33 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php @@ -25,7 +25,7 @@ class BooleanCheckboxWidget extends WidgetBase { */ public static function defaultSettings() { return array( - 'display_label' => FALSE, + 'display_label' => TRUE, ) + parent::defaultSettings(); } diff --git a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php index ee93c6e02ab..30f67d1e642 100644 --- a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php +++ b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php @@ -95,7 +95,8 @@ class BooleanFieldTest extends WebTestBase { // Display creation form. $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.'); - $this->assertRaw($on); + $this->assertText($this->field->label(), 'Uses field label by default.'); + $this->assertNoRaw($on, 'Does not use the "On" label.'); // Submit and ensure it is accepted. $edit = array( @@ -113,6 +114,21 @@ class BooleanFieldTest extends WebTestBase { $this->setRawContent(\Drupal::service('renderer')->renderRoot($content)); $this->assertRaw('
' . $on . '
'); + // Test with "On" label option. + entity_get_form_display('entity_test', 'entity_test', 'default') + ->setComponent($field_name, array( + 'type' => 'boolean_checkbox', + 'settings' => array( + 'display_label' => FALSE, + ) + )) + ->save(); + + $this->drupalGet('entity_test/add'); + $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.'); + $this->assertRaw($on); + $this->assertNoText($this->field->label()); + // Test if we can change the on label. $on = $this->randomMachineName(); $edit = array( @@ -123,21 +139,6 @@ class BooleanFieldTest extends WebTestBase { $this->drupalGet('entity_test/add'); $this->assertRaw($on); - // Test the display_label option. - entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( - 'type' => 'boolean_checkbox', - 'settings' => array( - 'display_label' => TRUE, - ) - )) - ->save(); - - $this->drupalGet('entity_test/add'); - $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.'); - $this->assertNoRaw($on); - $this->assertText($this->field->label()); - // Go to the form display page and check if the default settings works as // expected. $fieldEditUrl = 'entity_test/structure/entity_test/form-display';