You are here

protected function ParagraphsTestBaseTrait::addParagraphsTypeIcon in Paragraphs 8

Adds an icon to a paragraphs type.

Parameters

string $paragraphs_type: Machine name of the paragraph type to add the icon to.

Return value

\Drupal\file\Entity\File The file entity used as the icon.

1 call to ParagraphsTestBaseTrait::addParagraphsTypeIcon()
ParagraphsAddWidgetTest::testAddWidgetButton in tests/src/FunctionalJavascript/ParagraphsAddWidgetTest.php
Tests the add widget button with modal form.

File

tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php, line 122

Class

ParagraphsTestBaseTrait
Test trait for Paragraphs JS tests.

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript

Code

protected function addParagraphsTypeIcon($paragraphs_type) {

  // Get an image.
  $image_files = $this
    ->getTestFiles('image');
  $uri = current($image_files)->uri;

  // Create a copy of the image, so that multiple file entities don't
  // reference the same file.

  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  $copy_uri = $file_system
    ->copy($uri, 'public://' . $file_system
    ->basename($uri));

  // Create a new file entity.
  $file_entity = File::create([
    'uri' => $copy_uri,
  ]);
  $file_entity
    ->save();

  // Add the file entity to the paragraphs type as its icon.
  $paragraphs_type_entity = ParagraphsType::load($paragraphs_type);
  $paragraphs_type_entity
    ->set('icon_uuid', $file_entity
    ->uuid());
  $paragraphs_type_entity
    ->save();
  return $file_entity;
}