Ejemplo n.º 1
0
 /**
  * Implements Drupal\Core\Entity\EntityStorageInterface::save().
  *
  * @throws EntityMalformedException
  *   When attempting to save a configuration entity that has no ID.
  */
 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(SafeMarkup::format('Configuration entity ID @id exceeds maximum allowed length of @length characters.', array('@id' => $entity->get($this->idKey), '@length' => self::MAX_ID_LENGTH)));
     }
     return parent::save($entity);
 }
 /**
  * {@inheritdoc}
  */
 protected function invokeHook($hook, EntityInterface $entity)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     switch ($hook) {
         case 'presave':
             $this->invokeFieldMethod('preSave', $entity);
             break;
         case 'insert':
             $this->invokeFieldPostSave($entity, FALSE);
             break;
         case 'update':
             $this->invokeFieldPostSave($entity, TRUE);
             break;
     }
     parent::invokeHook($hook, $entity);
 }
 /**
  * Constructs a ContentEntityStorageBase object.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type definition.
  */
 public function __construct(EntityTypeInterface $entity_type)
 {
     parent::__construct($entity_type);
     $this->bundleKey = $this->entityType->getKey('bundle');
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 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);
 }
 /**
  * {@inheritdoc}
  */
 protected function invokeHook($hook, EntityInterface $entity)
 {
     if ($hook == 'presave') {
         $this->invokeFieldMethod('preSave', $entity);
     }
     parent::invokeHook($hook, $entity);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function save(EntityInterface $entity)
 {
     $transaction = $this->database->startTransaction();
     try {
         $return = parent::save($entity);
         // Ignore replica server temporarily.
         db_ignore_replica();
         return $return;
     } catch (\Exception $e) {
         $transaction->rollback();
         watchdog_exception($this->entityTypeId, $e);
         throw new EntityStorageException($e->getMessage(), $e->getCode(), $e);
     }
 }