function InlineBlockPrivateFilesTest::createPrivateFile

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockPrivateFilesTest::createPrivateFile()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockPrivateFilesTest::createPrivateFile()
  3. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockPrivateFilesTest::createPrivateFile()

Creates a private file.

Parameters

string $file_name: The file name.

Return value

\Drupal\Core\Entity\EntityInterface|\Drupal\file\Entity\File The file entity.

1 call to InlineBlockPrivateFilesTest::createPrivateFile()
InlineBlockPrivateFilesTest::testPrivateFiles in core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php
Tests access to private files added to inline blocks in the layout builder.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php, line 216

Class

InlineBlockPrivateFilesTest
Test access to private files in block fields on the Layout Builder.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function createPrivateFile($file_name) {
    // Create a new file entity.
    $file = File::create([
        'uid' => 1,
        'filename' => $file_name,
        'uri' => "private://{$file_name}",
        'filemime' => 'text/plain',
    ]);
    $file->setPermanent();
    file_put_contents($file->getFileUri(), $this->getFileSecret($file));
    $file->save();
    return $file;
}

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