/**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Saves the current Panels display in the tempstore or real storage..
  *
  * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
  *   The Panels display to be saved.
  * @param bool $temp
  *   Whether or not to save to temp store.
  *
  * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant
  *   The Panels display that was saved.
  *
  * @throws \Drupal\user\TempStoreException
  *   If there are any issues manipulating the entry in the temp store.
  */
 protected function savePanelsDisplay(PanelsDisplayVariant $panels_display, $temp = TRUE)
 {
     $temp_store_key = $panels_display->id();
     // Save configuration to temp store.
     if ($temp) {
         $this->tempStore->set($temp_store_key, $panels_display->getConfiguration());
     } else {
         // Check to see if temp store has configuration saved.
         if ($variant_config = $this->tempStore->get($temp_store_key)) {
             // Delete the existing temp store value.
             $this->tempStore->delete($temp_store_key);
         }
         // Save to the real storage.
         $this->panelsStorage->save($panels_display);
     }
     return $panels_display;
 }
 /**
  * {@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;
 }
Exemplo n.º 4
0
 /**
  * Deletes the given Panels Display from TempStore.
  *
  * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
  * @throws \Drupal\user\TempStoreException
  */
 protected function deletePanelsDisplayTempStore(PanelsDisplayVariant $panels_display)
 {
     $this->tempStore->delete($panels_display->id());
 }