function FieldStorageConfig::preSaveUpdated

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

Prepares saving an updated field definition.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage.

1 call to FieldStorageConfig::preSaveUpdated()
FieldStorageConfig::preSave in core/modules/field/src/Entity/FieldStorageConfig.php
Overrides \Drupal\Core\Entity\Entity::preSave().

File

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

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

protected function preSaveUpdated(EntityStorageInterface $storage) {
    $module_handler = \Drupal::moduleHandler();
    // Some updates are always disallowed.
    if ($this->getType() != $this->original
        ->getType()) {
        throw new FieldException(sprintf('Cannot change the field type for an existing field storage. The field storage %s has the type %s.', $this->id(), $this->original
            ->getType()));
    }
    if ($this->getTargetEntityTypeId() != $this->original
        ->getTargetEntityTypeId()) {
        throw new FieldException(sprintf('Cannot change the entity type for an existing field storage. The field storage %s has the type %s.', $this->id(), $this->original
            ->getTargetEntityTypeId()));
    }
    // 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', [
        $this,
        $this->original,
    ]);
    // Notify the field storage definition listener. A listener can reject the
    // definition update as invalid by raising an exception, which stops
    // execution before the definition is written to config.
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($this, $this->original);
}

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