You are here

public function Panelizer::getDefaultPanelsDisplay in Panelizer 8.5

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

Gets one default Panels display for an entity type, bundle and view mode.

Parameters

string $name: The name of the default.

string $entity_type_id: The entity type id.

string $bundle: The bundle.

string $view_mode: The view mode.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface|NULL $display: If the caller already has the correct display, it can optionally be passed in here so the Panelizer service doesn't have to look it up; otherwise, this argument can bo omitted.

Return value

\Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant|NULL The default Panels display with the given name if it exists; otherwise NULL.

Overrides PanelizerInterface::getDefaultPanelsDisplay

3 calls to Panelizer::getDefaultPanelsDisplay()
Panelizer::getDefaultPanelsDisplayByMachineName in src/Panelizer.php
Load a Panels Display via an ID (Machine Name).
Panelizer::getDefaultPanelsDisplays in src/Panelizer.php
Gets the default Panels displays for an entity type, bundle and view mode.
Panelizer::getPanelsDisplay in src/Panelizer.php
Gets the Panels display for a given entity and view mode.

File

src/Panelizer.php, line 363

Class

Panelizer
The Panelizer service.

Namespace

Drupal\panelizer

Code

public function getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
  if (!$display) {
    $display = $this
      ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);

    // If we still don't find a display, then we won't find a Panelizer
    // default for sure.
    if (!$display) {
      return NULL;
    }
  }
  $config = $display
    ->getThirdPartySetting('panelizer', 'displays', []);
  if (!empty($config[$name])) {

    // Set a default just in case.
    $config[$name]['builder'] = empty($config[$name]['builder']) ? 'standard' : $config[$name]['builder'];

    // @todo: validate schema after https://www.drupal.org/node/2392057 is fixed.
    $panels_display = $this->panelsManager
      ->importDisplay($config[$name], FALSE);
  }
  else {
    return NULL;
  }

  // @todo: Should be set when written, not here!
  $storage_id_parts = [
    $entity_type_id,
    $bundle,
    $view_mode,
    $name,
  ];
  $panels_display
    ->setStorage('panelizer_default', implode(':', $storage_id_parts));
  return $panels_display;
}