function FieldStorageConfig::preSave

Same name and namespace in other branches
  1. 9 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSave()
  2. 8.9.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSave()
  3. 11.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSave()

Overrides \Drupal\Core\Entity\Entity::preSave().

Throws

\Drupal\Core\Field\FieldException If the field definition is invalid.

\Drupal\Core\Entity\EntityStorageException In case of failures at the configuration storage level.

Overrides ConfigEntityBase::preSave

File

core/modules/field/src/Entity/FieldStorageConfig.php, line 317

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

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);
  }
  else {
    $this->preSaveUpdated($storage);
  }
  parent::preSave($storage);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.