protected function FieldInstance::saveUpdated

Saves an updated field instance definition.

Return value

SAVED_UPDATED if the definition was saved.

Throws

\Drupal\field\FieldException If the field instance definition is invalid.

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

1 call to FieldInstance::saveUpdated()
FieldInstance::save in drupal/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
Overrides \Drupal\Core\Entity\Entity::save().

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php, line 393
Contains \Drupal\field\Plugin\Core\Entity\FieldInstance.

Class

FieldInstance
Defines the Field instance entity.

Namespace

Drupal\field\Plugin\Core\Entity

Code

protected function saveUpdated() {
  $module_handler = \Drupal::moduleHandler();
  $instance_controller = \Drupal::entityManager()
    ->getStorageController($this->entityType);
  $original = $instance_controller
    ->loadUnchanged($this
    ->getOriginalID());

  // Some updates are always disallowed.
  if ($this->entity_type != $original->entity_type) {
    throw new FieldException("Cannot change an existing instance's entity_type.");
  }
  if ($this->bundle != $original->bundle && empty($this->bundle_rename_allowed)) {
    throw new FieldException("Cannot change an existing instance's bundle.");
  }
  if ($this->field_uuid != $original->field_uuid) {
    throw new FieldException("Cannot change an existing instance's field.");
  }

  // Ensure default values are present.
  $this
    ->prepareSave();

  // Save the configuration.
  $result = parent::save();
  field_cache_clear();

  // Invoke hook_field_update_instance() after the cache is cleared for API
  // consistency.
  $module_handler
    ->invokeAll('field_update_instance', array(
    $this,
    $original,
  ));
  return $result;
}