You are here

public function Panelizer::getEntityViewDisplay in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/Panelizer.php \Drupal\panelizer\Panelizer::getEntityViewDisplay()
  2. 8.4 src/Panelizer.php \Drupal\panelizer\Panelizer::getEntityViewDisplay()

Gets the entity view display for the entity type, bundle and view mode.

Parameters

$entity_type_id: The entity type id.

$bundle: The bundle.

$view_mode: The view mode.

Return value

\Drupal\Core\Entity\Display\EntityViewDisplayInterface|NULL The entity view display if one exists; NULL otherwise.

Overrides PanelizerInterface::getEntityViewDisplay

9 calls to Panelizer::getEntityViewDisplay()
Panelizer::getDefaultPanelsDisplay in src/Panelizer.php
Gets one default Panels display for an entity type, bundle and view mode.
Panelizer::getDefaultPanelsDisplays in src/Panelizer.php
Gets the default Panels displays for an entity type, bundle and view mode.
Panelizer::getDisplayStaticContexts in src/Panelizer.php
Panelizer::getPanelizerSettings in src/Panelizer.php
Get the Panelizer settings for an entity type, bundle and view mode.
Panelizer::isPanelized in src/Panelizer.php
Checks if the given entity type, bundle and view mode are panelized.

... See full list

File

src/Panelizer.php, line 161

Class

Panelizer
The Panelizer service.

Namespace

Drupal\panelizer

Code

public function getEntityViewDisplay($entity_type_id, $bundle, $view_mode) {

  // Check the existence and status of:
  // - the display for the view mode,
  // - the 'default' display.
  $candidate_ids = [];
  if ($view_mode != 'default') {
    $candidate_ids[] = $entity_type_id . '.' . $bundle . '.' . $view_mode;
  }
  $candidate_ids[] = $entity_type_id . '.' . $bundle . '.default';
  $results = \Drupal::entityQuery('entity_view_display')
    ->condition('id', $candidate_ids)
    ->condition('status', TRUE)
    ->execute();

  // Select the first valid candidate display, if any.
  $load_id = FALSE;
  foreach ($candidate_ids as $candidate_id) {
    if (isset($results[$candidate_id])) {
      $load_id = $candidate_id;
      break;
    }
  }

  // Use the selected display if any, or create a fresh runtime object.
  $storage = $this->entityTypeManager
    ->getStorage('entity_view_display');
  if ($load_id) {
    $display = $storage
      ->load($load_id);
  }
  else {
    $display = $storage
      ->create([
      'targetEntityType' => $entity_type_id,
      'bundle' => $bundle,
      'mode' => $view_mode,
      'status' => TRUE,
    ]);
  }

  // Let modules alter the display.
  $display_context = [
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'view_mode' => $view_mode,
  ];
  $this->moduleHandler
    ->alter('entity_view_display', $display, $display_context);
  return $display;
}