/**
  * Compiles settings needed for the IPE to function.
  *
  * @param array $regions
  *   The render array representing regions.
  * @param \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout
  *   The current layout.
  * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
  *   The Panels display we are editing.
  * @param bool $unsaved
  *   Whether or not there are unsaved changes.
  *
  * @return array|bool
  *   An associative array representing the contents of drupalSettings, or
  *   FALSE if there was an error.
  */
 protected function getDrupalSettings(array $regions, LayoutInterface $layout, PanelsDisplayVariant $panels_display, $unsaved)
 {
     $settings = ['regions' => []];
     // Add current block IDs to settings sorted by region.
     foreach ($regions as $region => $blocks) {
         $settings['regions'][$region] = ['name' => $region, 'label' => '', 'blocks' => []];
         if (!$blocks) {
             continue;
         }
         /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
         foreach ($blocks as $block_uuid => $block) {
             $configuration = $block->getConfiguration();
             $setting = ['uuid' => $block_uuid, 'label' => $block->label(), 'id' => $block->getPluginId()];
             $settings['regions'][$region]['blocks'][$block_uuid] = NestedArray::mergeDeep($configuration, $setting);
         }
     }
     // Add the layout information.
     $layout_definition = $layout->getPluginDefinition();
     $settings['layout'] = ['id' => $layout->getPluginId(), 'label' => $layout_definition['label'], 'original' => true];
     // Add the display variant's config.
     $settings['panels_display'] = ['storage_type' => $panels_display->getStorageType(), 'storage_id' => $panels_display->getStorageId(), 'id' => $panels_display->id()];
     // Inform the App of our saved state.
     $settings['unsaved'] = $unsaved;
     return $settings;
 }
 /**
  * Assigns the layout plugin to this variant.
  *
  * @param string|\Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout
  *   The layout plugin object or plugin id.
  * @param array $layout_settings
  *   The layout configuration.
  *
  * @return $this
  *
  * @throws \Exception
  *   If $layout isn't a string or LayoutInterface object.
  */
 public function setLayout($layout, array $layout_settings = [])
 {
     if ($layout instanceof LayoutInterface) {
         $this->layout = $layout;
         $this->configuration['layout'] = $layout->getPluginId();
         $this->configuration['layout_settings'] = $layout_settings;
     } elseif (is_string($layout)) {
         $this->layout = NULL;
         $this->configuration['layout'] = $layout;
         $this->configuration['layout_settings'] = $layout_settings;
     } else {
         throw new \Exception("Layout must be a string or LayoutInterface object");
     }
     return $this;
 }
 /**
  * @covers ::getRegionNames
  */
 public function testGetRegionNames()
 {
     $region_names = ['Foo', 'Bar', 'Baz'];
     $this->layout->getPluginDefinition()->willReturn(['region_names' => $region_names]);
     $this->assertSame($region_names, $this->variant->getRegionNames());
 }
 /**
  * {@inheritdoc}
  */
 public function build(array $regions, array $contexts, LayoutInterface $layout = NULL)
 {
     $regions = $this->buildRegions($regions, $contexts);
     if ($layout) {
         $regions = $layout->build($regions);
     }
     return $regions;
 }