function FieldStorageConfig::preSaveNew
Same name in other branches
- 9 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSaveNew()
- 8.9.x core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSaveNew()
- 10 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preSaveNew()
Prepares saving a new field definition.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage.
Throws
\Drupal\Core\Field\FieldException If the field definition is invalid.
1 call to FieldStorageConfig::preSaveNew()
- FieldStorageConfig::preSave in core/
modules/ field/ src/ Entity/ FieldStorageConfig.php - Overrides \Drupal\Core\Entity\EntityBase::preSave().
File
-
core/
modules/ field/ src/ Entity/ FieldStorageConfig.php, line 347
Class
- FieldStorageConfig
- Defines the Field storage configuration entity.
Namespace
Drupal\field\EntityCode
protected function preSaveNew(EntityStorageInterface $storage) {
$entity_field_manager = \Drupal::service('entity_field.manager');
// Assign the ID.
$this->id = $this->id();
// Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH
// characters. We use mb_strlen() because the DB layer assumes that column
// widths are given in characters rather than bytes.
if (mb_strlen($this->getName()) > static::NAME_MAX_LENGTH) {
throw new FieldException('Attempt to create a field storage with an name longer than ' . static::NAME_MAX_LENGTH . ' characters: ' . $this->getName());
}
// Disallow reserved field names.
$disallowed_field_names = array_keys($entity_field_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId()));
if (in_array($this->getName(), $disallowed_field_names)) {
throw new FieldException("Attempt to create field storage {$this->getName()} which is reserved by entity type {$this->getTargetEntityTypeId()}.");
}
// Notify the field storage definition listener.
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.