You are here

function media_acquiadam_entity_get_display in Media: Acquia DAM 8

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

This is an exact copy of the deprecated entity_get_display() from Core 8.6.x.

@todo Eliminate this in favor of \Drupal::service('entity_display.repository')->getViewDisplay() in Core 8.8.x once that is the lowest supported version.

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.

See also

\Drupal\Core\Entity\EntityStorageInterface::create()

\Drupal\Core\Entity\EntityStorageInterface::load()

File

./media_acquiadam.install, line 250
Installation related hooks and functions.

Code

function media_acquiadam_entity_get_display($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;
}