Commit bbc47f05 authored by catch's avatar catch

Issue #2434745 by geertvd: Boolean field: On/Off labels are in the "storage"...

Issue #2434745 by geertvd: Boolean field: On/Off labels are in the "storage" settings but shouldn't be
parent 17e18270
...@@ -582,9 +582,9 @@ field.value.entity_reference: ...@@ -582,9 +582,9 @@ field.value.entity_reference:
# Schema for the configuration of the Boolean field type. # Schema for the configuration of the Boolean field type.
field.storage_settings.boolean: field.field_settings.boolean:
type: mapping
label: 'Boolean settings' label: 'Boolean settings'
type: mapping
mapping: mapping:
on_label: on_label:
type: string type: string
...@@ -593,10 +593,6 @@ field.storage_settings.boolean: ...@@ -593,10 +593,6 @@ field.storage_settings.boolean:
type: string type: string
label: 'Off label' label: 'Off label'
field.field_settings.boolean:
label: 'Boolean settings'
type: mapping
field.value.boolean: field.value.boolean:
type: mapping type: mapping
mapping: mapping:
......
...@@ -31,11 +31,11 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface { ...@@ -31,11 +31,11 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultStorageSettings() { public static function defaultFieldSettings() {
return array( return array(
'on_label' => t('On'), 'on_label' => t('On'),
'off_label' => t('Off'), 'off_label' => t('Off'),
) + parent::defaultStorageSettings(); ) + parent::defaultFieldSettings();
} }
/** /**
...@@ -66,7 +66,9 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) ...@@ -66,7 +66,9 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$element['on_label'] = array( $element['on_label'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('"On" label'), '#title' => $this->t('"On" label'),
......
...@@ -69,10 +69,6 @@ function testBooleanField() { ...@@ -69,10 +69,6 @@ function testBooleanField() {
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'type' => 'boolean', 'type' => 'boolean',
'settings' => array(
'on_label' => $on,
'off_label' => $off,
),
)); ));
$this->field_storage->save(); $this->field_storage->save();
$this->field = FieldConfig::create(array( $this->field = FieldConfig::create(array(
...@@ -81,6 +77,10 @@ function testBooleanField() { ...@@ -81,6 +77,10 @@ function testBooleanField() {
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'label' => $label, 'label' => $label,
'required' => TRUE, 'required' => TRUE,
'settings' => array(
'on_label' => $on,
'off_label' => $off,
),
)); ));
$this->field->save(); $this->field->save();
...@@ -118,6 +118,16 @@ function testBooleanField() { ...@@ -118,6 +118,16 @@ function testBooleanField() {
$this->setRawContent(drupal_render($content)); $this->setRawContent(drupal_render($content));
$this->assertRaw('<div class="field-item">' . $on . '</div>'); $this->assertRaw('<div class="field-item">' . $on . '</div>');
// Test if we can change the on label.
$on = $this->randomMachineName();
$edit = array(
'field[settings][on_label]' => $on,
);
$this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name, $edit, t('Save settings'));
// Check if we see the updated labels in the creation form.
$this->drupalGet('entity_test/add');
$this->assertRaw($on);
// Test the display_label option. // Test the display_label option.
entity_get_form_display('entity_test', 'entity_test', 'default') entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array( ->setComponent($field_name, array(
...@@ -168,9 +178,9 @@ function testBooleanField() { ...@@ -168,9 +178,9 @@ function testBooleanField() {
); );
// Test the boolean field settings. // Test the boolean field settings.
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage'); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
$this->assertFieldById('edit-field-storage-settings-on-label', $on); $this->assertFieldById('edit-field-settings-on-label', $on);
$this->assertFieldById('edit-field-storage-settings-off-label', $off); $this->assertFieldById('edit-field-settings-off-label', $off);
} }
} }
...@@ -111,11 +111,11 @@ function testBooleanFormatterSettings() { ...@@ -111,11 +111,11 @@ function testBooleanFormatterSettings() {
foreach ($settings as $values) { foreach ($settings as $values) {
// Set up the field settings. // Set up the field settings.
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName . '/storage'); $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
$this->drupalPostForm(NULL, array( $this->drupalPostForm(NULL, array(
'field_storage[settings][on_label]' => $values[0], 'field[settings][on_label]' => $values[0],
'field_storage[settings][off_label]' => $values[1], 'field[settings][off_label]' => $values[1],
), 'Save field settings'); ), 'Save settings');
// Open the Manage Display page and trigger the field settings form. // Open the Manage Display page and trigger the field settings form.
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display'); $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
......
...@@ -16,6 +16,8 @@ default_value: ...@@ -16,6 +16,8 @@ default_value:
- -
value: 0 value: 0
default_value_callback: '' default_value_callback: ''
settings: { } settings:
on_label: Yes
off_label: No
third_party_settings: { } third_party_settings: { }
field_type: boolean field_type: boolean
...@@ -7,9 +7,7 @@ id: taxonomy_term.forum_container ...@@ -7,9 +7,7 @@ id: taxonomy_term.forum_container
field_name: forum_container field_name: forum_container
entity_type: taxonomy_term entity_type: taxonomy_term
type: boolean type: boolean
settings: settings: { }
on_label: Yes
off_label: No
module: core module: core
locked: true locked: true
cardinality: 1 cardinality: 1
......
...@@ -58,10 +58,6 @@ protected function setUp() { ...@@ -58,10 +58,6 @@ protected function setUp() {
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'boolean', 'type' => 'boolean',
'cardinality' => 1, 'cardinality' => 1,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
)); ));
$field_storage->save(); $field_storage->save();
...@@ -71,6 +67,10 @@ protected function setUp() { ...@@ -71,6 +67,10 @@ protected function setUp() {
'widget' => array( 'widget' => array(
'type' => 'options_buttons', 'type' => 'options_buttons',
), ),
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
))->save(); ))->save();
// After enabling a node access module, the access table has to be rebuild. // After enabling a node access module, the access table has to be rebuild.
......
...@@ -56,10 +56,6 @@ protected function setUp() { ...@@ -56,10 +56,6 @@ protected function setUp() {
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'boolean', 'type' => 'boolean',
'cardinality' => 1, 'cardinality' => 1,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
)); ));
$field_storage->save(); $field_storage->save();
...@@ -69,6 +65,10 @@ protected function setUp() { ...@@ -69,6 +65,10 @@ protected function setUp() {
'widget' => array( 'widget' => array(
'type' => 'options_buttons', 'type' => 'options_buttons',
), ),
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
))->save(); ))->save();
// After enabling a node access module, the access table has to be rebuild. // After enabling a node access module, the access table has to be rebuild.
......
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