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

8.2.x
xjm 2016-06-23 12:32:50 +02:00
parent 97464a9c54
commit a1529fe90f
2 changed files with 18 additions and 17 deletions

View File

@ -25,7 +25,7 @@ class BooleanCheckboxWidget extends WidgetBase {
*/
public static function defaultSettings() {
return array(
'display_label' => FALSE,
'display_label' => TRUE,
) + parent::defaultSettings();
}

View File

@ -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('<div class="field__item">' . $on . '</div>');
// 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';