Issue #2434745 by geertvd: Boolean field: On/Off labels are in the "storage" settings but shouldn't be

8.0.x
Nathaniel Catchpole 2015-03-04 15:17:04 +00:00
parent 17e182707b
commit bbc47f05fc
8 changed files with 40 additions and 32 deletions

View File

@ -582,9 +582,9 @@ field.value.entity_reference:
# Schema for the configuration of the Boolean field type.
field.storage_settings.boolean:
type: mapping
field.field_settings.boolean:
label: 'Boolean settings'
type: mapping
mapping:
on_label:
type: string
@ -593,10 +593,6 @@ field.storage_settings.boolean:
type: string
label: 'Off label'
field.field_settings.boolean:
label: 'Boolean settings'
type: mapping
field.value.boolean:
type: mapping
mapping:

View File

@ -31,11 +31,11 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface {
/**
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
public static function defaultFieldSettings() {
return array(
'on_label' => t('On'),
'off_label' => t('Off'),
) + parent::defaultStorageSettings();
) + parent::defaultFieldSettings();
}
/**
@ -66,7 +66,9 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface {
/**
* {@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(
'#type' => 'textfield',
'#title' => $this->t('"On" label'),

View File

@ -69,10 +69,6 @@ class BooleanFieldTest extends WebTestBase {
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'boolean',
'settings' => array(
'on_label' => $on,
'off_label' => $off,
),
));
$this->field_storage->save();
$this->field = FieldConfig::create(array(
@ -81,6 +77,10 @@ class BooleanFieldTest extends WebTestBase {
'bundle' => 'entity_test',
'label' => $label,
'required' => TRUE,
'settings' => array(
'on_label' => $on,
'off_label' => $off,
),
));
$this->field->save();
@ -118,6 +118,16 @@ class BooleanFieldTest extends WebTestBase {
$this->setRawContent(drupal_render($content));
$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.
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
@ -168,9 +178,9 @@ class BooleanFieldTest extends WebTestBase {
);
// Test the boolean field settings.
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage');
$this->assertFieldById('edit-field-storage-settings-on-label', $on);
$this->assertFieldById('edit-field-storage-settings-off-label', $off);
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
$this->assertFieldById('edit-field-settings-on-label', $on);
$this->assertFieldById('edit-field-settings-off-label', $off);
}
}

View File

@ -111,11 +111,11 @@ class BooleanFormatterSettingsTest extends WebTestBase {
foreach ($settings as $values) {
// 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(
'field_storage[settings][on_label]' => $values[0],
'field_storage[settings][off_label]' => $values[1],
), 'Save field settings');
'field[settings][on_label]' => $values[0],
'field[settings][off_label]' => $values[1],
), 'Save settings');
// Open the Manage Display page and trigger the field settings form.
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');

View File

@ -16,6 +16,8 @@ default_value:
-
value: 0
default_value_callback: ''
settings: { }
settings:
on_label: Yes
off_label: No
third_party_settings: { }
field_type: boolean

View File

@ -7,9 +7,7 @@ id: taxonomy_term.forum_container
field_name: forum_container
entity_type: taxonomy_term
type: boolean
settings:
on_label: Yes
off_label: No
settings: { }
module: core
locked: true
cardinality: 1

View File

@ -58,10 +58,6 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
));
$field_storage->save();
@ -71,6 +67,10 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
'widget' => array(
'type' => 'options_buttons',
),
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
))->save();
// After enabling a node access module, the access table has to be rebuild.

View File

@ -56,10 +56,6 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
));
$field_storage->save();
@ -69,6 +65,10 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
'widget' => array(
'type' => 'options_buttons',
),
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
))->save();
// After enabling a node access module, the access table has to be rebuild.