public function 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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!KeyValueStore!KeyValueEntityStorage.php/function/KeyValueEntityStorage::save/8.1.x