/** * @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()); }
/** * 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; }