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