Пример #1
0
 /**
  * Checks if the user has access to underlying storage for a Panels display.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $panels_storage_type = $route_match->getParameter('panels_storage_type');
     $panels_storage_id = $route_match->getParameter('panels_storage_id');
     $op = $route->getRequirement('_panels_storage_access');
     return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account);
 }
 /**
  * Takes the current Page Variant and returns a possibly modified Page Variant
  * based on what's in TempStore for this user.
  *
  * @param string $panels_storage_type
  *   The Panels storage plugin which holds the Panels display.
  * @param string $panels_storage_id
  *   The id within the Panels storage plugin for this Panels display.
  *
  * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant|NULL
  */
 protected function loadPanelsDisplay($panels_storage_type, $panels_storage_id)
 {
     /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
     $panels_display = $this->panelsStorage->load($panels_storage_type, $panels_storage_id);
     // If a temporary configuration for this variant exists, use it.
     if ($variant_config = $this->tempStore->get($panels_display->id())) {
         $panels_display->setConfiguration($variant_config);
     }
     return $panels_display;
 }
Пример #3
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') && $this->panelsStorage->access($panels_display->getStorageType(), $panels_display->getStorageId(), 'update', $this->account)->isAllowed();
     // 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;
 }
Пример #5
0
 /**
  * Deletes TempStore and saves the current Panels display.
  *
  * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
  *   The Panels display to be saved.
  *
  * @throws \Drupal\user\TempStoreException
  *   If there are any issues manipulating the entry in the temp store.
  */
 protected function savePanelsDisplay(PanelsDisplayVariant $panels_display)
 {
     $this->deletePanelsDisplayTempStore($panels_display);
     $this->panelsStore->save($panels_display);
 }