function FileFieldWidgetTest::createTemporaryFile

Creates a temporary file, for a specific user.

Parameters

string $data: A string containing the contents of the file.

\Drupal\user\UserInterface $user: The user of the file owner.

Return value

\Drupal\file\FileInterface A file object, or FALSE on error.

1 call to FileFieldWidgetTest::createTemporaryFile()
FileFieldWidgetTest::doTestTemporaryFileRemovalExploit in core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
Helper for testing exploiting the temporary file removal using fid.

File

core/modules/file/tests/src/Functional/FileFieldWidgetTest.php, line 57

Class

FileFieldWidgetTest
Tests the file field widget with public and private files.

Namespace

Drupal\Tests\file\Functional

Code

protected function createTemporaryFile($data, UserInterface $user = NULL) {
  $file = file_save_data($data, NULL, NULL);
  if ($file) {
    if ($user) {
      $file->setOwner($user);
    }
    else {
      $file->setOwner($this->adminUser);
    }
    // Change the file status to be temporary.
    $file->setTemporary();
    // Save the changes.
    $file->save();
  }
  return $file;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.