FieldStorageConfig::preSaveUpdated

protected FieldStorageConfig::preSaveUpdated(EntityStorageInterface $storage)

Prepares saving an updated field definition.

Parameters

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

File

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

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

protected function preSaveUpdated(EntityStorageInterface $storage) {
  $module_handler = \Drupal::moduleHandler();
  $entity_manager = \Drupal::entityManager();

  // Some updates are always disallowed.
  if ($this->getType() != $this->original->getType()) {
    throw new FieldException("Cannot change the field type for an existing field storage.");
  }
  if ($this->getTargetEntityTypeId() != $this->original->getTargetEntityTypeId()) {
    throw new FieldException("Cannot change the entity type for an existing field storage.");
  }

  // 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));

  // Notify the entity manager. A listener can reject the definition
  // update as invalid by raising an exception, which stops execution before
  // the definition is written to config.
  $entity_manager->onFieldStorageDefinitionUpdate($this, $this->original);
}
doc_Drupal
2016-10-29 09:12:24
Comments
Leave a Comment

Please login to continue.