You are here

public function Panelizer::setDisplayStaticContexts in Panelizer 8.4

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

Overrides PanelizerInterface::setDisplayStaticContexts

File

src/Panelizer.php, line 437

Class

Panelizer
The Panelizer service.

Namespace

Drupal\panelizer

Code

public function setDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode, $contexts) {
  $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 Panels display's static contexts.
  $panels_displays = $display
    ->getThirdPartySetting('panelizer', 'displays', []);
  $panels_displays[$name]['static_context'] = $contexts;
  $display
    ->setThirdPartySetting('panelizer', 'displays', $panels_displays);
  $display
    ->save();
}