You are here

protected function DynamicEntityReferenceFormatterTest::getEntityDisplay in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/DynamicEntityReferenceFormatterTest.php \Drupal\Tests\dynamic_entity_reference\Kernel\DynamicEntityReferenceFormatterTest::getEntityDisplay()

Returns the entity view display associated with a bundle and view mode.

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $view_mode: The view mode, or 'default' to retrieve the 'default' display object for this bundle.

Return value

\Drupal\Core\Entity\Display\EntityViewDisplayInterface The entity view display associated with the view mode.

File

tests/src/Kernel/DynamicEntityReferenceFormatterTest.php, line 428

Class

DynamicEntityReferenceFormatterTest
Tests the formatters functionality.

Namespace

Drupal\Tests\dynamic_entity_reference\Kernel

Code

protected function getEntityDisplay($entity_type, $bundle, $view_mode) {

  // Try loading the display from configuration.
  $display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $view_mode);

  // If not found, create a fresh display object. We do not preemptively
  // create new entity_view_display configuration entries for each existing
  // entity type and bundle whenever a new view mode becomes available.
  // Instead, configuration entries are only created when a display object is
  // explicitly configured and saved.
  if (!$display) {
    $display = EntityViewDisplay::create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => $view_mode,
      'status' => TRUE,
    ]);
  }
  return $display;
}