FieldConfig::preSave

public FieldConfig::preSave(EntityStorageInterface $storage)

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/FieldConfig.php, line 143

Class

FieldConfig
Defines the Field entity.

Namespace

Drupal\field\Entity

Code

public function preSave(EntityStorageInterface $storage) {
  $entity_manager = \Drupal::entityManager();
  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');

  $storage_definition = $this->getFieldStorageDefinition();

  // 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.
  $default_settings = $field_type_manager->getDefaultFieldSettings($storage_definition->getType());
  $this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;

  if ($this->isNew()) {
    // Notify the entity storage.
    $entity_manager->onFieldDefinitionCreate($this);
  }
  else {
    // Some updates are always disallowed.
    if ($this->entity_type != $this->original->entity_type) {
      throw new FieldException("Cannot change an existing field's entity_type.");
    }
    if ($this->bundle != $this->original->bundle) {
      throw new FieldException("Cannot change an existing field's bundle.");
    }
    if ($storage_definition->uuid() != $this->original->getFieldStorageDefinition()->uuid()) {
      throw new FieldException("Cannot change an existing field's storage.");
    }
    // Notify the entity storage.
    $entity_manager->onFieldDefinitionUpdate($this, $this->original);
  }

  parent::preSave($storage);
}
doc_Drupal
2016-10-29 09:10:41
Comments
Leave a Comment

Please login to continue.