Commit 03d3d538 authored by catch's avatar catch

Issue #2368349 by Gábor Hojtsy, alexpott: Entity view and form display...

Issue #2368349 by Gábor Hojtsy, alexpott: Entity view and form display configuration schemas are too verbose / key ones missing
parent bfe4403f
......@@ -650,6 +650,9 @@ field.integer.field_settings:
suffix:
type: string
label: 'Suffix'
size:
type: string
label: 'Database storage size'
field.integer.value:
type: sequence
......
......@@ -18,6 +18,9 @@ entity_field_view_display_base:
label:
type: string
label: 'Label setting machine name'
settings:
type: sequence
label: 'Settings'
# Schema for the base of the form mode display format settings.
entity_field_form_display_base:
......@@ -34,3 +37,6 @@ entity_field_form_display_base:
label: 'Third party settings'
sequence:
- type: entity_form_display.third_party.[%key]
settings:
type: sequence
label: 'Settings'
......@@ -145,35 +145,52 @@ entity_form_display.field.string_textfield:
type: label
label: 'Placeholder'
entity_form_display.field.datetime_timestamp:
entity_form_display.field.string_textarea:
type: entity_field_form_display_base
label: 'Datetime timestamp display format settings'
label: 'Textarea display format settings'
mapping:
settings:
type: sequence
type: mapping
label: 'Settings'
sequence:
- type: string
mapping:
rows:
type: integer
label: 'Rows'
placeholder:
type: label
label: 'Placeholder'
entity_form_display.field.email_default:
type: entity_field_form_display_base
label: 'Email field display format settings'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
placeholder:
type: label
label: 'Placeholder'
entity_form_display.field.datetime_timestamp:
type: entity_field_form_display_base
label: 'Datetime timestamp display format settings'
entity_form_display.field.boolean_checkbox:
type: entity_field_form_display_base
label: 'Boolean checkbox display format settings'
mapping:
settings:
type: sequence
type: mapping
label: 'Settings'
sequence:
- type: string
mapping:
display_label:
type: boolean
label: 'Display label'
entity_form_display.field.hidden:
type: entity_field_form_display_base
label: '- Hidden - format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_form_display.field.number:
type: entity_field_form_display_base
......@@ -238,29 +255,11 @@ entity_view_display.field.number_integer:
entity_view_display.field.number_unformatted:
type: entity_field_view_display_base
label: 'Number unformatted display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.uri_link:
type: entity_field_view_display_base
label: 'URI as link display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.timestamp_ago:
type: entity_field_view_display_base
label: 'Timestamp ago display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
......@@ -154,8 +154,9 @@ public function prepareConfiguration($field_type, array $configuration) {
$field_type = $this->fieldTypeManager->getDefinition($field_type);
$configuration['type'] = $field_type['default_formatter'];
}
// Fill in default settings values for the formatter.
$configuration['settings'] += $this->getDefaultSettings($configuration['type']);
// Filter out unknown settings, and fill in defaults for missing settings.
$default_settings = $this->getDefaultSettings($configuration['type']);
$configuration['settings'] = array_intersect_key($configuration['settings'], $default_settings) + $default_settings;
return $configuration;
}
......
......@@ -153,8 +153,9 @@ public function prepareConfiguration($field_type, array $configuration) {
$field_type = $this->fieldTypeManager->getDefinition($field_type);
$configuration['type'] = $field_type['default_widget'];
}
// Fill in default settings values for the widget.
$configuration['settings'] += $this->getDefaultSettings($configuration['type']);
// Filter out unknown settings, and fill in defaults for missing settings.
$default_settings = $this->getDefaultSettings($configuration['type']);
$configuration['settings'] = array_intersect_key($configuration['settings'], $default_settings) + $default_settings;
return $configuration;
}
......
......@@ -36,13 +36,13 @@ content:
promote:
type: boolean_checkbox
settings:
display_label: '1'
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: '1'
display_label: true
weight: 16
third_party_settings: { }
body:
......
......@@ -5,20 +5,16 @@ entity_view_display.field.comment_default:
label: 'Comment display format settings'
mapping:
settings:
type: sequence
type: mapping
label: 'Settings'
sequence:
- type: string
mapping:
pager_id:
type: integer
label: 'Pager ID'
entity_form_display.field.comment_default:
type: entity_field_form_display_base
label: 'Comment display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
action.configuration.comment_publish_action:
type: action_configuration_default
......
......@@ -41,12 +41,6 @@ entity_view_display.field.datetime_default:
entity_view_display.field.datetime_plain:
type: entity_field_view_display_base
label: 'Datetime plain display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_form_display.field.datetime_datelist:
type: entity_field_form_display_base
......@@ -69,9 +63,3 @@ entity_form_display.field.datetime_datelist:
entity_form_display.field.datetime_default:
type: entity_field_form_display_base
label: 'Datetime default display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
......@@ -9,8 +9,8 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\simpletest\WebTestBase;
/**
* Tests Datetime field functionality.
......@@ -19,6 +19,15 @@
*/
class DateTimeFieldTest extends WebTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......@@ -141,6 +150,7 @@ function testDateField() {
// Verify that the plain formatter works.
$this->display_options['type'] = 'datetime_plain';
$this->display_options['settings'] = array();
entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options)
->save();
......@@ -206,6 +216,7 @@ function testDatetimeField() {
// Verify that the plain formatter works.
$this->display_options['type'] = 'datetime_plain';
$this->display_options['settings'] = array();
entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options)
->save();
......
......@@ -55,12 +55,6 @@ entity_view_display.field.entity_reference_entity_view:
entity_view_display.field.entity_reference_entity_id:
type: entity_field_view_display_base
label: 'Entity reference entity ID display format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.entity_reference_label:
type: entity_field_view_display_base
......
......@@ -17,6 +17,15 @@
*/
class EmailFieldTest extends WebTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......
......@@ -17,6 +17,15 @@
*/
class NumberFieldTest extends WebTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......@@ -49,7 +58,7 @@ function testNumberDecimalField() {
'entity_type' => 'entity_test',
'type' => 'decimal',
'settings' => array(
'precision' => 8, 'scale' => 4, 'decimal_separator' => '.',
'precision' => 8, 'scale' => 4,
)
))->save();
entity_create('field_config', array(
......
<?php
/**
* @file
* Definition of \Drupal\field\Tests\String\StringFieldTest.
*/
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\Unicode;
use Drupal\simpletest\WebTestBase;
/**
* Tests the creation of string fields.
*
* @group text
*/
class StringFieldTest extends WebTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('entity_test');
protected $web_user;
protected function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content'));
$this->drupalLogin($this->web_user);
}
// Test fields.
/**
* Test widgets.
*/
function testTextfieldWidgets() {
$this->_testTextfieldWidgets('string', 'string_textfield');
$this->_testTextfieldWidgets('string_long', 'string_textarea');
}
/**
* Helper function for testTextfieldWidgets().
*/
function _testTextfieldWidgets($field_type, $widget_type) {
// Create a field.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $field_type
));
$field_storage->save();
entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => $widget_type,
'settings' => array(
'placeholder' => 'A placeholder on ' . $widget_type,
),
))
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($field_name)
->save();
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
$this->assertNoFieldByName("{$field_name}[0][format]", '1', 'Format selector is not displayed');
$this->assertRaw(format_string('placeholder="A placeholder on !widget_type"', array('!widget_type' => $widget_type)));
// Submit with some value.
$value = $this->randomMachineName();
$edit = array(
"{$field_name}[0][value]" => $value,
);
$this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
// Display the entity.
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->drupalSetContent(drupal_render($content));
$this->assertText($value, 'Filtered tags are not displayed');
}
}
......@@ -9,6 +9,9 @@ entity_view_display.field.field_test_multiple:
test_formatter_setting_multiple:
type: string
label: 'Test setting'
alter:
type: boolean
label: 'Test altering'
entity_form_display.field.test_field_widget_multiple:
type: entity_field_form_display_base
......
......@@ -32,6 +32,7 @@ class TestFieldMultipleFormatter extends FormatterBase {
public static function defaultSettings() {
return array(
'test_formatter_setting_multiple' => 'dummy test string',
'alter' => FALSE,
) + parent::defaultSettings();
}
......
......@@ -70,43 +70,18 @@ field.file.field_settings:
entity_view_display.field.file_default:
type: entity_field_view_display_base
label: 'Generic file format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.file_rss_enclosure:
type: entity_field_view_display_base
label: 'RSS enclosure format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.file_table:
type: entity_field_view_display_base
label: 'Table of files format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_view_display.field.file_url_plain:
type: entity_field_view_display_base
label: 'URL to file format settings'
mapping:
settings:
type: sequence
label: 'Settings'
sequence:
- type: string
entity_form_display.field.file_generic:
type: entity_field_form_display_base
......
......@@ -39,13 +39,13 @@ content:
promote:
type: boolean_checkbox
settings:
display_label: '1'
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: '1'
display_label: true
weight: 16
third_party_settings: { }
comment_forum:
......
......@@ -28,7 +28,7 @@ content:
type: comment_default
weight: 20
settings:
pager_id: '0'
pager_id: 0
third_party_settings: { }
body:
label: hidden
......
......@@ -34,6 +34,7 @@ image.effect.image_crop:
mapping:
anchor:
label: 'Anchor'
type: string
image.effect.image_resize:
type: image_size
......@@ -48,6 +49,7 @@ image.effect.image_rotate:
label: 'Rotation angle'
bgcolor:
label: 'Background color'
type: color_hex
random:
type: boolean
label: 'Randomize'
......@@ -60,6 +62,10 @@ image.effect.image_scale:
type: boolean
label: 'Upscale'
# The image desaturate effect has no settings.
image.effect.image_desaturate:
type: sequence
image.effect.image_scale_and_crop:
type: image_size
label: 'Image scale and crop'
......@@ -139,10 +145,15 @@ entity_view_display.field.image:
label: 'Image field display format settings'
mapping:
settings:
type: sequence
label: 'Format settings'
sequence:
- type: string
type: mapping
label: 'Settings'
mapping:
image_link:
type: string
label: 'Link image to'
image_style:
type: string
label: 'Image style'
entity_form_display.field.image_image:
type: entity_field_form_display_base
......@@ -150,7 +161,7 @@ entity_form_display.field.image_image:
mapping:
settings:
type: mapping
label: 'Format settings'
label: 'Settings'
mapping:
progress_indicator:
type: string
......
......@@ -27,6 +27,15 @@
*/
abstract class ImageFieldTestBase extends WebTestBase {
/**
* Set to TRUE to strict check all configuration saved.
*
* @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = TRUE;
/**
* Modules to enable.
*
......@@ -72,13 +81,15 @@ function createImageField($name, $type_name, $storage_settings = array(), $field
'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
))->save();
$description = !empty($field_settings['description']) ? $field_settings['description'] : '';
unset($field_settings['description']);
$field_config = entity_create('field_config', array(
'field_name' => $name,
'label' => $name,
'entity_type' => 'node',
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'description' => !empty($field_settings['description']) ? $field_settings['description'] : '',
'description' => $description,
'settings' => $field_settings,
));
$field_config->save();
......
......@@ -57,9 +57,9 @@ process:
plain: string
number_integer:
default: number_integer
us_0: number_integer
be_0: number_integer
fr_0: number_integer
us_3: number_integer
be_3: number_integer
fr_3: number_integer
unformatted: number_unformatted
number_float:
default: number_decimal
......@@ -196,6 +196,9 @@ process:
decimal_separator: .
thousand_separator: ','
prefix_suffix: true
us_3:
thousand_separator: ','
prefix_suffix: true
be_0:
scale: 0
decimal_separator: ','
......@@ -211,6 +214,9 @@ process:
decimal_separator: ','
thousand_separator: .
prefix_suffix: true
be_3:
thousand_separator: .
prefix_suffix: true
fr_0:
scale: 0
decimal_separator: ','
......@@ -226,6 +232,9 @@ process:
decimal_separator: ','
thousand_separator: ' '
prefix_suffix: true
fr_3:
thousand_separator: ' '
prefix_suffix: true
link:
default:
trim_length: '80'
......
......@@ -197,7 +197,7 @@ public function load() {
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'format' => 'us_3',
'exclude' => 0,
),
4 => array(
......@@ -708,7 +708,7 @@ public function load() {
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'format' => 'us_3',
'exclude' => 0,
),
4 => array(
......@@ -808,7 +808,7 @@ public function load() {
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'format' => 'us_3',
'exclude' => 0,
),
4 => array(
......@@ -840,7 +840,7 @@ public function load() {
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'format' => 'us_3',
'exclude' => 0,
),
4 => array(
......
......@@ -116,8 +116,6 @@ public function testEntityDisplaySettings() {
$expected['weight'] = 2;
$expected['type'] = 'number_integer';
$expected['settings'] = array(
'scale' => 0,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
......@@ -126,6 +124,7 @@ public function testEntityDisplaySettings() {
$expected['weight'] = 3;
$expected['type'] = 'number_decimal';
$expected['settings']['scale'] = 2;
$expe