You are here

protected function BlazyCreationTestTrait::setUpFormatterDisplay in Blazy 8.2

Same name and namespace in other branches
  1. 8 tests/src/Traits/BlazyCreationTestTrait.php \Drupal\Tests\blazy\Traits\BlazyCreationTestTrait::setUpFormatterDisplay()

Setup formatter displays, default to image, and update its settings.

Parameters

string $bundle: The bundle name.

array $data: May contain formatter settings to be added to defaults.

Return value

\Drupal\Core\Entity\Entity\EntityViewDisplay The formatter display instance.

5 calls to BlazyCreationTestTrait::setUpFormatterDisplay()
BlazyBlazyJavaScriptTest::testFormatterDisplay in tests/src/FunctionalJavascript/BlazyBlazyJavaScriptTest.php
Test the Blazy element from loading to loaded states.
BlazyCreationTestTrait::setUpContentWithEntityReference in tests/src/Traits/BlazyCreationTestTrait.php
Build dummy contents with entity references.
BlazyFormatterTest::setUp in tests/src/Kernel/BlazyFormatterTest.php
Set the default field storage backend for fields created during tests.
BlazyIoJavaScriptTest::testFormatterDisplay in tests/src/FunctionalJavascript/BlazyIoJavaScriptTest.php
Test the Blazy element from loading to loaded states.
BlazyViewsFileTest::buildContents in tests/src/Kernel/Views/BlazyViewsFileTest.php
Build contents.

File

tests/src/Traits/BlazyCreationTestTrait.php, line 40

Class

BlazyCreationTestTrait
A Trait common for Blazy tests.

Namespace

Drupal\Tests\blazy\Traits

Code

protected function setUpFormatterDisplay($bundle = '', array $data = []) {
  $view_mode = empty($data['view_mode']) ? 'default' : $data['view_mode'];
  $plugin_id = empty($data['plugin_id']) ? $this->testPluginId : $data['plugin_id'];
  $field_name = empty($data['field_name']) ? $this->testFieldName : $data['field_name'];
  $settings = empty($data['settings']) ? [] : $data['settings'];
  $display_id = $this->entityType . '.' . $bundle . '.' . $view_mode;
  $storage = $this->blazyManager
    ->getEntityTypeManager()
    ->getStorage('entity_view_display');
  $display = $storage
    ->load($display_id);
  if (!$display) {
    $values = [
      'targetEntityType' => $this->entityType,
      'bundle' => $bundle,
      'mode' => $view_mode,
      'status' => TRUE,
    ];
    $display = $storage
      ->create($values);
  }
  $settings['current_view_mode'] = $settings['view_mode'] = $view_mode;
  $display
    ->setComponent($field_name, [
    'type' => $plugin_id,
    'settings' => $settings,
    'label' => 'hidden',
  ]);
  $display
    ->save();
  return $display;
}