diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php index 7f7e6be..eaba0f9 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -270,6 +270,15 @@ public function postCreate(EntityStorageInterface $storage) { /** * {@inheritdoc} */ + public function preSave(EntityStorageInterface $storage) { + // Filter out unknown settings. + $default_settings = $this->getFieldStorageDefinition()->getSettings(); + $this->settings = array_intersect_key($this->settings, $default_settings); + } + + /** + * {@inheritdoc} + */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Clear the cache. $this->entityManager()->clearCachedFieldDefinitions(); diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 6b89e38..9ae0fc4 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -253,6 +253,13 @@ public function preSave(EntityStorageInterface $storage) { // Clear the derived data about the field. unset($this->schema); + // Filter out unknown settings and make sure all settings are present, so + // 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->getDefaultStorageSettings($this->type); + $this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings; + if ($this->isNew()) { $this->preSaveNew($storage); } @@ -303,10 +310,6 @@ protected function preSaveNew(EntityStorageInterface $storage) { } $this->module = $field_type['provider']; - // Make sure all settings are present, so that a complete field - // definition is passed to the various hooks and written to config. - $this->settings += $field_type_manager->getDefaultStorageSettings($this->type); - // Notify the entity manager. $entity_manager->onFieldStorageDefinitionCreate($this); } @@ -333,7 +336,6 @@ public function calculateDependencies() { protected function preSaveUpdated(EntityStorageInterface $storage) { $module_handler = \Drupal::moduleHandler(); $entity_manager = \Drupal::entityManager(); - $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); // Some updates are always disallowed. if ($this->type != $this->original->type) { @@ -343,10 +345,6 @@ protected function preSaveUpdated(EntityStorageInterface $storage) { throw new FieldException("Cannot change the entity type for an existing field storage."); } - // Make sure all settings are present, so that a complete field - // definition is passed to the various hooks and written to config. - $this->settings += $field_type_manager->getDefaultStorageSettings($this->type); - // See if any module forbids the update by throwing an exception. This // invokes hook_field_storage_config_update_forbid(). $module_handler->invokeAll('field_storage_config_update_forbid', array($this, $this->original));