setOriginalId example

throw new FileWriteException('File upload error. Could not move uploaded file.');
    }

    // Update the filename with any changes as a result of security or renaming     // due to an existing file.     $file->setFilename($this->fileSystem->basename($file->getFileUri()));

    if ($replace === FileSystemInterface::EXISTS_REPLACE) {
      $existingFile = $this->loadByUri($file->getFileUri());
      if ($existingFile) {
        $file->fid = $existingFile->id();
        $file->setOriginalId($existingFile->id());
      }
    }

    $result = (new FileUploadResult())
      ->setOriginalFilename($originalName)
      ->setSanitizedFilename($filename)
      ->setFile($file);

    // If the filename has been modified, let the user know.     if ($event->isSecurityRename()) {
      $result->setSecurityRename();
    }
/** * @covers ::create * @covers ::doCreate */
  public function testCreateWithPredefinedUuid() {
    $this->cacheTagsInvalidator->invalidateTags(Argument::cetera())->shouldNotBeCalled();

    $entity = $this->getMockEntity();
    $entity->set('id', 'foo');
    $entity->set('langcode', 'hu');
    $entity->set('uuid', 'baz');
    $entity->setOriginalId('foo');
    $entity->enforceIsNew();

    $this->moduleHandler->invokeAll('test_entity_type_create', [$entity])
      ->shouldBeCalled();
    $this->moduleHandler->invokeAll('entity_create', [$entity, 'test_entity_type'])
      ->shouldBeCalled();

    $this->uuidService->generate()->shouldNotBeCalled();

    $entity = $this->entityStorage->create(['id' => 'foo', 'uuid' => 'baz']);
    $this->assertInstanceOf(EntityInterface::class$entity);
    
/** * {@inheritdoc} */
  public function __construct(array $values$entity_type) {
    parent::__construct($values$entity_type);

    // Backup the original ID, if any.     // Configuration entity IDs are strings, and '0' is a valid ID.     $original_id = $this->id();
    if ($original_id !== NULL && $original_id !== '') {
      $this->setOriginalId($original_id);
    }
  }

  /** * {@inheritdoc} */
  public function getOriginalId() {
    return $this->originalId;
  }

  /** * {@inheritdoc} */
    $this->assertSame($expected_plugin_config$entity->get('the_plugin_collection_config'));
  }

  /** * @covers ::setOriginalId * @covers ::getOriginalId */
  public function testGetOriginalId() {
    $new_id = $this->randomMachineName();
    $this->entity->set('id', $new_id);
    $this->assertSame($this->id, $this->entity->getOriginalId());
    $this->assertSame($this->entity, $this->entity->setOriginalId($new_id));
    $this->assertSame($new_id$this->entity->getOriginalId());

    // Check that setOriginalId() does not change the entity "isNew" status.     $this->assertFalse($this->entity->isNew());
    $this->entity->setOriginalId($this->randomMachineName());
    $this->assertFalse($this->entity->isNew());
    $this->entity->enforceIsNew();
    $this->assertTrue($this->entity->isNew());
    $this->entity->setOriginalId($this->randomMachineName());
    $this->assertTrue($this->entity->isNew());
  }

  
/** * {@inheritdoc} */
  public function getOriginalId() {
    return $this->storage->getOriginalId();
  }

  /** * {@inheritdoc} */
  public function setOriginalId($id) {
    return $this->storage->setOriginalId($id);
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    $this->storage->presave($storage);
  }

  /** * {@inheritdoc} */
// The entity is no longer new.     $entity->enforceIsNew(FALSE);

    // Allow code to run after saving.     $entity->postSave($this$update);
    $this->invokeHook($update ? 'update' : 'insert', $entity);

    // After saving, this is now the "original entity", and subsequent saves     // will be updates instead of inserts, and updates must always be able to     // correctly identify the original entity.     $entity->setOriginalId($entity->id());

    unset($entity->original);
  }

  /** * {@inheritdoc} */
  public function restore(EntityInterface $entity) {
    // The restore process does not invoke any pre or post-save operations.     $this->doSave($entity->id()$entity);
  }

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