public function ConfigEntityStorage::save

public ConfigEntityStorage::save(EntityInterface $entity)

Implements Drupal\Core\Entity\EntityStorageInterface::save().

Throws

EntityMalformedException When attempting to save a configuration entity that has no ID.

Overrides EntityStorageBase::save

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php, line 244

Class

ConfigEntityStorage
Defines the storage class for configuration entities.

Namespace

Drupal\Core\Config\Entity

Code

public function save(EntityInterface $entity) {
  // Configuration entity IDs are strings, and '0' is a valid ID.
  $id = $entity->id();
  if ($id === NULL || $id === '') {
    throw new EntityMalformedException('The entity does not have an ID.');
  }

  // Check the configuration entity ID length.
  // @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH
  // @todo Consider moving this to a protected method on the parent class, and
  //   abstracting it for all entity types.
  if (strlen($entity->get($this->idKey)) > self::MAX_ID_LENGTH) {
    throw new ConfigEntityIdLengthException("Configuration entity ID {$entity->get($this->idKey)} exceeds maximum allowed length of " . self::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!Config!Entity!ConfigEntityStorage.php/function/ConfigEntityStorage::save/8.1.x