public function KeyValueEntityStorage::save in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage::save()
Saves the entity permanently.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to save.
Return value
SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed.
Throws
\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.
Overrides EntityStorageBase::save
File
- core/
lib/ Drupal/ Core/ Entity/ KeyValueStore/ KeyValueEntityStorage.php, line 155
Class
- KeyValueEntityStorage
- Provides a key value backend for entities.
Namespace
Drupal\Core\Entity\KeyValueStoreCode
public function save(EntityInterface $entity) {
$id = $entity
->id();
if ($id === NULL || $id === '') {
throw new EntityMalformedException('The entity does not have an ID.');
}
// Check the entity ID length.
// @todo This is not config-specific, but serial IDs will likely never hit
// this limit. Consider renaming the exception class.
if (strlen($entity
->id()) > static::MAX_ID_LENGTH) {
throw new ConfigEntityIdLengthException("Entity ID {$entity->id()} exceeds maximum allowed length of " . static::MAX_ID_LENGTH . ' characters.');
}
return parent::save($entity);
}