/** * @covers ::save * * @expectedException \Exception * @expectedExceptionMessage Page variant doesn't use a Panels display variant */ public function testSaveNotPanels() { $this->storage->load('not_a_panel')->willReturn($this->pageVariantNotPanels->reveal()); $this->panelsDisplay->setConfiguration(Argument::cetera())->shouldNotBeCalled(); $this->pageVariant->save()->shouldNotBeCalled(); $panels_display = $this->prophesize(PanelsDisplayVariant::class); $panels_display->getStorageId()->willReturn('not_a_panel'); $panels_display->getConfiguration()->shouldNotBeCalled(); $panels_storage = new PageManagerPanelsStorage([], '', [], $this->entityTypeManager->reveal()); $panels_storage->save($panels_display->reveal()); }
/** * Loads or creates a Block Plugin instance suitable for rendering or testing. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Block\BlockPluginInterface * The Block Plugin instance. */ protected function getBlockInstance(FormStateInterface $form_state) { // If a UUID is provided, the Block should already exist. if ($uuid = $form_state->getValue('uuid')) { // If a temporary configuration for this variant exists, use it. $temp_store_key = $this->panelsDisplay->id(); if ($variant_config = $this->tempStore->get($temp_store_key)) { $this->panelsDisplay->setConfiguration($variant_config); } // Load the existing Block instance. $block_instance = $this->panelsDisplay->getBlock($uuid); } else { // Create an instance of this Block plugin. /** @var \Drupal\Core\Block\BlockBase $block_instance */ $block_instance = $this->blockManager->createInstance($form_state->getValue('plugin_id')); } return $block_instance; }
/** * {@inheritdoc} */ public function build(PanelsDisplayVariant $panels_display) { // Check to see if the current user has permissions to use the IPE. $has_permission = $this->account->hasPermission('access panels in-place editing'); // Attach the Panels In-place editor library based on permissions. if ($has_permission) { // This flag tracks whether or not there are unsaved changes. $unsaved = FALSE; // If a temporary configuration for this variant exists, use it. $temp_store_key = $panels_display->id(); if ($variant_config = $this->tempStore->get($temp_store_key)) { unset($variant_config['id']); $panels_display->setConfiguration($variant_config); // Indicate that the user is viewing un-saved changes. $unsaved = TRUE; } $build = parent::build($panels_display); $regions = $panels_display->getRegionAssignments(); $layout = $panels_display->getLayout(); foreach ($regions as $region => $blocks) { // Wrap each region with a unique class and data attribute. $region_name = Html::getClass("block-region-{$region}"); $build[$region]['#prefix'] = '<div class="' . $region_name . '" data-region-name="' . $region . '">'; $build[$region]['#suffix'] = '</div>'; if ($blocks) { foreach ($blocks as $block_id => $block) { $build[$region][$block_id]['#attributes']['data-block-id'] = $block_id; } } } // Attach the required settings and IPE. $build['#attached']['library'][] = 'panels_ipe/panels_ipe'; $build['#attached']['drupalSettings']['panels_ipe'] = $this->getDrupalSettings($regions, $layout, $panels_display, $unsaved); // Add our custom elements to the build. $build['#prefix'] = '<div id="panels-ipe-content">'; $build['#suffix'] = '</div><div id="panels-ipe-tray"></div>'; } else { $build = parent::build($panels_display); } return $build; }