EntityMalformedException example

public function label() {
    if (($label_key = $this->getEntityType()->getKey('label')) && isset($this->{$label_key})) {
      return $this->{$label_key};
    }
  }

  /** * {@inheritdoc} */
  public function toUrl($rel = 'canonical', array $options = []) {
    if ($this->id() === NULL) {
      throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId()));
    }

    // The links array might contain URI templates set in annotations.     $link_templates = $this->linkTemplates();

    // Links pointing to the current revision point to the actual entity. So     // instead of using the 'revision' link, use the 'canonical' link.     if ($rel === 'revision' && $this instanceof RevisionableInterface && $this->isDefaultRevision()) {
      $rel = 'canonical';
    }

    
/** * Implements Drupal\Core\Entity\EntityStorageInterface::save(). * * @throws \Drupal\Core\Entity\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($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);
  }
public function doDelete($entities) {
    $entity_ids = array_keys($entities);
    $this->keyValueStore->deleteMultiple($entity_ids);
  }

  /** * {@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);
  }

  

    elseif (!$entity->isNew() && empty($this->value)) {
      // If the password is empty, that means it was not changed, so use the       // original password.       $this->value = $entity->original->{$this->getFieldDefinition()->getName()}->value;
    }
    elseif ($entity->isNew() || (strlen(trim($this->value)) > 0 && $this->value != $entity->original->{$this->getFieldDefinition()->getName()}->value)) {
      // Allow alternate password hashing schemes.       $this->value = \Drupal::service('password')->hash(trim($this->value));
      // Abort if the hashing failed and returned FALSE.       if (!$this->value) {
        throw new EntityMalformedException('The entity does not have a password.');
      }
    }

    // Ensure that the existing password is unset to minimise risks of it     // getting serialized and stored somewhere.     $this->existing = NULL;
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.