Commit 7822393c authored by catch's avatar catch
Browse files

Issue #2370305 by Gábor Hojtsy, yched: Refactor field type configuration...

Issue #2370305 by Gábor Hojtsy, yched: Refactor field type configuration schemas for DX, easier to find errors
parent 6714300a
...@@ -378,12 +378,16 @@ field_config_base: ...@@ -378,12 +378,16 @@ field_config_base:
type: boolean type: boolean
label: 'Translatable' label: 'Translatable'
default_value: default_value:
type: field.[%parent.field_type].value type: sequence
label: 'Default values'
sequence:
- type: field.value.[%parent.%parent.field_type]
label: 'Default value'
default_value_callback: default_value_callback:
type: string type: string
label: 'Default value callback' label: 'Default value callback'
settings: settings:
type: field.[%parent.field_type].field_settings type: field.field_settings.[%parent.field_type]
third_party_settings: third_party_settings:
type: sequence type: sequence
label: 'Third party settings' label: 'Third party settings'
...@@ -417,9 +421,23 @@ core.date_format.*: ...@@ -417,9 +421,23 @@ core.date_format.*:
type: string type: string
label: 'Default language' label: 'Default language'
# Generic field settings schemas.
field.storage_settings.*:
type: mapping
label: 'Settings'
field.field_settings.*:
type: mapping
label: 'Settings'
field.value.*:
type: mapping
label: 'Default value'
# Schema for the configuration of the String field type. # Schema for the configuration of the String field type.
field.string.storage_settings: field.storage_settings.string:
type: mapping type: mapping
label: 'String settings' label: 'String settings'
mapping: mapping:
...@@ -427,45 +445,39 @@ field.string.storage_settings: ...@@ -427,45 +445,39 @@ field.string.storage_settings:
type: integer type: integer
label: 'Maximum length' label: 'Maximum length'
field.string.field_settings: field.field_settings.string:
type: sequence type: mapping
label: 'String settings' label: 'String settings'
field.string.value: field.value.string:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: string
mapping: label: 'Value'
value:
type: string
label: 'Value'
# Schema for the configuration of the String (long) field type. # Schema for the configuration of the String (long) field type.
field.string_long.storage_settings: field.storage_settings.string_long:
type: field.string.storage_settings type: field.storage_settings.string
label: 'String (long) settings' label: 'String (long) settings'
field.string_long.field_settings: field.field_settings.string_long:
type: field.string.field_settings type: field.field_settings.string
label: 'String (long) settings' label: 'String (long) settings'
field.string_long.value: field.value.string_long:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: text
mapping: label: 'Value'
value:
type: text
label: 'Value'
# Schema for the configuration of the URI field type. # Schema for the configuration of the URI field type.
field.uri.storage_settings: field.storage_settings.uri:
type: mapping type: mapping
label: 'URI settings' label: 'URI settings'
mapping: mapping:
...@@ -473,66 +485,57 @@ field.uri.storage_settings: ...@@ -473,66 +485,57 @@ field.uri.storage_settings:
type: integer type: integer
label: 'Maximum length' label: 'Maximum length'
field.uri.field_settings: field.field_settings.uri:
type: sequence type: mapping
label: 'URI settings' label: 'URI settings'
field.uri.value: field.value.uri:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: string
mapping: label: 'Value'
value:
type: string
label: 'Value'
# Schema for the configuration of the Created field type. # Schema for the configuration of the Created field type.
field.created.storage_settings: field.storage_settings.created:
type: sequence type: mapping
label: 'Created timestamp settings' label: 'Created timestamp settings'
field.created.field_settings: field.field_settings.created:
type: sequence type: mapping
label: 'Created timestamp settings' label: 'Created timestamp settings'
field.created.value: field.value.created:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: integer
mapping: label: 'Value'
value:
type: integer
label: 'Value'
# Schema for the configuration of the Changed field type. # Schema for the configuration of the Changed field type.
field.changed.storage_settings: field.storage_settings.changed:
type: sequence type: mapping
label: 'Changed timestamp settings' label: 'Changed timestamp settings'
field.changed.field_settings: field.field_settings.changed:
type: sequence type: mapping
label: 'Changed timestamp settings' label: 'Changed timestamp settings'
field.changed.value: field.value.changed:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: integer
mapping: label: 'Value'
value:
type: integer
label: 'Value'
# Schema for the configuration of the Entity reference field type. # Schema for the configuration of the Entity reference field type.
field.entity_reference.storage_settings: field.storage_settings.entity_reference:
type: mapping type: mapping
label: 'Entity reference settings' label: 'Entity reference settings'
mapping: mapping:
...@@ -540,7 +543,7 @@ field.entity_reference.storage_settings: ...@@ -540,7 +543,7 @@ field.entity_reference.storage_settings:
type: string type: string
label: 'Type of item to reference' label: 'Type of item to reference'
field.entity_reference.field_settings: field.field_settings.entity_reference:
type: mapping type: mapping
label: 'Entity reference settings' label: 'Entity reference settings'
mapping: mapping:
...@@ -551,23 +554,20 @@ field.entity_reference.field_settings: ...@@ -551,23 +554,20 @@ field.entity_reference.field_settings:
type: entity_reference.[%parent.handler].handler_settings type: entity_reference.[%parent.handler].handler_settings
label: 'Reference method settings' label: 'Reference method settings'
field.entity_reference.value: field.value.entity_reference:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping target_id:
label: 'Default' type: string
mapping: label: 'Value'
target_id: target_uuid:
type: string type: string
label: 'Value' label: 'Target UUID'
target_uuid:
type: string
label: 'Target UUID'
# Schema for the configuration of the Boolean field type. # Schema for the configuration of the Boolean field type.
field.boolean.storage_settings: field.storage_settings.boolean:
type: mapping type: mapping
label: 'Boolean settings' label: 'Boolean settings'
mapping: mapping:
...@@ -578,50 +578,41 @@ field.boolean.storage_settings: ...@@ -578,50 +578,41 @@ field.boolean.storage_settings:
type: string type: string
label: 'Off label' label: 'Off label'
field.boolean.field_settings: field.field_settings.boolean:
label: 'Boolean settings' label: 'Boolean settings'
type: sequence type: mapping
field.boolean.value: field.value.boolean:
type: sequence type: mapping
label: 'Default value' mapping:
sequence: value:
- type: mapping type: integer
label: 'Default' label: 'Value'
mapping:
value:
type: integer
label: 'Value'
# Schema for the configuration of the Email field type. # Schema for the configuration of the Email field type.
field.email.storage_settings: field.storage_settings.email:
type: sequence type: mapping
label: 'Email settings' label: 'Email settings'
sequence:
- type: string
field.email.field_settings: field.field_settings.email:
type: sequence type: mapping
label: 'Email settings' label: 'Email settings'
sequence: sequence:
- type: string - type: string
label: 'Setting' label: 'Setting'
field.email.value: field.value.email:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default' type: email
mapping: label: 'Value'
value:
type: email
label: 'Value'
# Schema for the configuration of the Integer field type. # Schema for the configuration of the Integer field type.
field.integer.storage_settings: field.storage_settings.integer:
type: mapping type: mapping
label: 'Integer settings' label: 'Integer settings'
mapping: mapping:
...@@ -632,7 +623,7 @@ field.integer.storage_settings: ...@@ -632,7 +623,7 @@ field.integer.storage_settings:
type: string type: string
label: 'Database storage size' label: 'Database storage size'
field.integer.field_settings: field.field_settings.integer:
type: mapping type: mapping
label: 'Integer' label: 'Integer'
mapping: mapping:
...@@ -649,20 +640,17 @@ field.integer.field_settings: ...@@ -649,20 +640,17 @@ field.integer.field_settings:
type: string type: string
label: 'Suffix' label: 'Suffix'
field.integer.value: field.value.integer:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default value' type: integer
mapping: label: 'Value'
value:
type: integer
label: 'Value'
# Schema for the configuration of the Decimal field type. # Schema for the configuration of the Decimal field type.
field.decimal.storage_settings: field.storage_settings.decimal:
type: mapping type: mapping
label: 'Decimal settings' label: 'Decimal settings'
mapping: mapping:
...@@ -673,9 +661,9 @@ field.decimal.storage_settings: ...@@ -673,9 +661,9 @@ field.decimal.storage_settings:
type: integer type: integer
label: 'Scale' label: 'Scale'
field.decimal.field_settings: field.field_settings.decimal:
type: mapping type: mapping
label: 'Decimal' label: 'Decimal settings'
mapping: mapping:
min: min:
type: float type: float
...@@ -690,29 +678,23 @@ field.decimal.field_settings: ...@@ -690,29 +678,23 @@ field.decimal.field_settings:
type: string type: string
label: 'Suffix' label: 'Suffix'
field.decimal.value: field.value.decimal:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default value' type: float
mapping: label: 'Value'
value:
type: float
label: 'Value'
# Schema for the configuration of the Float field type. # Schema for the configuration of the Float field type.
field.float.storage_settings: field.storage_settings.float:
type: sequence type: mapping
label: 'Float settings' label: 'Float settings'
sequence:
- type: string
label: 'setting'
field.float.field_settings: field.field_settings.float:
type: mapping type: mapping
label: 'Float' label: 'Float settings'
mapping: mapping:
min: min:
type: float type: float
...@@ -727,16 +709,13 @@ field.float.field_settings: ...@@ -727,16 +709,13 @@ field.float.field_settings:
type: string type: string
label: 'Suffix' label: 'Suffix'
field.float.value: field.value.float:
type: sequence type: mapping
label: 'Default value' label: 'Default value'
sequence: mapping:
- type: mapping value:
label: 'Default value' type: float
mapping: label: 'Value'
value:
type: float
label: 'Value'
# Text with a text format. # Text with a text format.
text_format: text_format:
......
...@@ -154,8 +154,12 @@ protected function getBaseFieldDefinition() { ...@@ -154,8 +154,12 @@ protected function getBaseFieldDefinition() {
* BaseFieldOverride::allowBundleRename() has not been called. * BaseFieldOverride::allowBundleRename() has not been called.
*/ */
public function preSave(EntityStorageInterface $storage) { public function preSave(EntityStorageInterface $storage) {
// Set the default instance settings. // Filter out unknown settings and make sure all settings are present, so
$this->settings += \Drupal::service('plugin.manager.field.field_type')->getDefaultFieldSettings($this->getType()); // that a complete field definition is passed to the various hooks and
// written to config.
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$default_settings = $field_type_manager->getDefaultFieldSettings($this->getType());
$this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;
// Call the parent's presave method to perform validate and calculate // Call the parent's presave method to perform validate and calculate
// dependencies. // dependencies.
......
...@@ -52,40 +52,38 @@ comment.type.*: ...@@ -52,40 +52,38 @@ comment.type.*:
type: text type: text
label: 'Description' label: 'Description'
field.comment.storage_settings: field.storage_settings.comment:
type: sequence type: mapping
label: 'Settings' label: 'Comment settings'
sequence: mapping:
- type: string comment_type:
label: 'Setting' label: 'Comment type'
type: string
field.comment.value: field.value.comment:
type: sequence type: mapping
label: 'Settings' label: 'Default value'
sequence: mapping:
- type: mapping status:
label: 'Settings' type: integer
mapping: label: 'Comment status'
status: cid:
type: integer type: integer
label: 'Status' label: 'Last comment ID'
cid: last_comment_timestamp:
type: integer type: integer
label: 'Status' label: 'Last comment timestamp'
last_comment_timestamp: last_comment_name:
type: integer type: integer
label: 'Last comment timestamp' label: 'Last comment name'
last_comment_name: last_comment_uid:
type: integer type: integer
label: 'Name' label: 'Last comment user ID'
last_comment_uid: comment_count:
type: integer type: integer
label: 'UID' label: 'Number of comments'
comment_count:
type: integer
label: 'Count'
field.comment.field_settings: field.field_settings.comment:
type: mapping