You are here

function lightning_core_entity_get_display in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.4 lightning_core.module \lightning_core_entity_get_display()

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 except for one change: the default value of the $view_mode parameter.

@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()

2 calls to lightning_core_entity_get_display()
lightning_page_modules_installed in modules/lightning_page/lightning_page.module
Implements hook_modules_installed().
Update360Test::test in tests/src/Kernel/Update/Update360Test.php

File

./lightning_core.module, line 312
Contains core functionality for the Lightning distribution.

Code

function lightning_core_entity_get_display($entity_type, $bundle, $view_mode = 'default') {

  // 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;
}