replaceNodeFile example

// Check that the file exists on disk and in the database.     $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    $node_file_r1 = File::load($node->{$field_name}->target_id);
    $node_vid_r1 = $node->getRevisionId();
    $this->assertFileExists($node_file_r1->getFileUri());
    $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.');
    $this->assertFileIsPermanent($node_file_r1, 'File is permanent.');

    // Upload another file to the same node in a new revision.     $this->replaceNodeFile($test_file$field_name$nid);
    $node_storage->resetCache([$nid]);
    $node = $node_storage->load($nid);
    $node_file_r2 = File::load($node->{$field_name}->target_id);
    $node_vid_r2 = $node->getRevisionId();
    $this->assertFileExists($node_file_r2->getFileUri());
    $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.');
    $this->assertFileIsPermanent($node_file_r2, 'Replacement file is permanent.');

    // Check that the original file is still in place on the first revision.     $node = $node_storage->loadRevision($node_vid_r1);
    $current_file = File::load($node->{$field_name}->target_id);
    
Home | Imprint | This part of the site doesn't use cookies.