KeyValueEntityStorage::save

public KeyValueEntityStorage::save(EntityInterface $entity)

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 151

Class

KeyValueEntityStorage
Provides a key value backend for entities.

Namespace

Drupal\Core\Entity\KeyValueStore

Code

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);
}
doc_Drupal
2016-10-29 09:21:46
Comments
Leave a Comment

Please login to continue.