You are here

public function Panelizer::setDefaultPanelsDisplay in Panelizer 8.4

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

Parameters

$name: The name of the default.

$entity_type_id: The entity type id.

$bundle: The bundle.

$view_mode: The view mode.

\Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display: The Panels display to use as the default.

Throws

\Drupal\panelizer\Exception\PanelizerException When a display can't be found for the given entity type, bundle and view mode.

Overrides PanelizerInterface::setDefaultPanelsDisplay

File

src/Panelizer.php, line 400

Class

Panelizer
The Panelizer service.

Namespace

Drupal\panelizer

Code

public function setDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, PanelsDisplayVariant $panels_display) {
  $display = $this
    ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
  if (!$display) {
    throw new PanelizerException("Unable to find display for given entity type, bundle and view mode");
  }

  // Set this individual Panels display.
  $panels_displays = $display
    ->getThirdPartySetting('panelizer', 'displays', []);
  $panels_displays[$name] = $this->panelsManager
    ->exportDisplay($panels_display);
  $display
    ->setThirdPartySetting('panelizer', 'displays', $panels_displays);
  $display
    ->save();
}