You are here

function easy_email_get_entity_display in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x easy_email.module \easy_email_get_entity_display()

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

The entity display will be created if missing.

Borrowed from Drupal Commerce: commerce_get_entity_display()

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

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to easy_email_get_entity_display()
easy_email_create_field in ./easy_email.module
Creates a configurable field from the given field definition.

File

./easy_email.module, line 948
Contains easy_email.module.

Code

function easy_email_get_entity_display($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));
  }
  $storage = \Drupal::entityTypeManager()
    ->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;
}