You are here

protected function BundleEntityDuplicatorTest::getDisplay in Entity API 8

Gets the entity display for the given entity type and bundle.

The entity display will be created if missing.

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $display_context: The display context ('view' or 'form').

Return value

\Drupal\Core\Entity\Display\EntityDisplayInterface The entity display.

Throws

\InvalidArgumentException Thrown when an invalid display context is provided.

2 calls to BundleEntityDuplicatorTest::getDisplay()
BundleEntityDuplicatorTest::testDuplicateDisplays in tests/src/Kernel/BundleEntityDuplicatorTest.php
@covers ::duplicateDisplays
BundleEntityDuplicatorTest::testDuplicateWithFieldAndDisplays in tests/src/Kernel/BundleEntityDuplicatorTest.php
@covers ::duplicate @covers ::duplicateFields @covers ::duplicateDisplays

File

tests/src/Kernel/BundleEntityDuplicatorTest.php, line 270

Class

BundleEntityDuplicatorTest
Tests the bundle entity duplicator.

Namespace

Drupal\Tests\entity\Kernel

Code

protected function getDisplay($entity_type, $bundle, $display_context) {
  if (!in_array($display_context, [
    'view',
    'form',
  ])) {
    throw new \InvalidArgumentException(sprintf('Invalid display_context %s passed to _commerce_product_get_display().', $display_context));
  }
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $storage = $entity_type_manager
    ->getStorage('entity_' . $display_context . '_display');
  $display = $storage
    ->load($entity_type . '.' . $bundle . '.default');
  if (!$display) {
    $display = $storage
      ->create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => 'default',
      'status' => TRUE,
    ]);
  }
  return $display;
}