ConfigEntityIdLengthException example

// 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($id) > static::MAX_ID_LENGTH) {
      throw new ConfigEntityIdLengthException("Configuration entity ID {$id} exceeds maximum allowed length of " . static::MAX_ID_LENGTH . " characters.");
    }

    return parent::save($entity);
  }

  /** * {@inheritdoc} */
  protected function doSave($id, EntityInterface $entity) {
    $is_new = $entity->isNew();
    $prefix = $this->getPrefix();
    

  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 doSave($id, EntityInterface $entity) {
    $is_new = $entity->isNew();

    // Save the entity data in the key value store.
return $this->entityTypeManager()->getDefinition($this->getEntityTypeId());
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    // Check if this is an entity bundle.     if ($this->getEntityType()->getBundleOf()) {
      // Throw an exception if the bundle ID is longer than 32 characters.       if (mb_strlen($this->id()) > EntityTypeInterface::BUNDLE_MAX_LENGTH) {
        throw new ConfigEntityIdLengthException("Attempt to create a bundle with an ID longer than " . EntityTypeInterface::BUNDLE_MAX_LENGTH . " characters: $this->id().");
      }
    }
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    $this->invalidateTagsOnSave($update);
  }

  
Home | Imprint | This part of the site doesn't use cookies.