Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function getOptions(RouteMatchInterface $route_match)
 {
     $options = parent::getOptions($route_match);
     // Append the current path as destination to the query string.
     $options['query']['destination'] = $this->redirectDestination->get();
     return $options;
 }
 /**
  * Redirects login attempts on already-logged-in session to the destination.
  */
 public function onRespond(FilterResponseEvent $event)
 {
     // Return early in most cases.
     if ($event->getRequest()->getMethod() !== 'POST') {
         return;
     }
     if (!$this->currentUser->isAuthenticated()) {
         return;
     }
     if (!$event->isMasterRequest()) {
         return;
     }
     if (!$event->getRequest()->query->has('destination')) {
         return;
     }
     if ($event->getResponse() instanceof RedirectResponse) {
         return;
     }
     // There has to be a better way to figure out if we landed on the 403/404 page.
     $page_403 = $this->configFactory->get('system.site')->get('page.403');
     $page_404 = $this->configFactory->get('system.site')->get('page.404');
     $path = $this->currentPath->getPath();
     $route = $this->currentRouteMatch->getRouteName();
     if ($route == 'system.403' || $page_403 && $path == $page_403 || $route == 'system.404' || $page_404 && $path == $page_404) {
         // RedirectResponseSubscriber will convert to absolute URL for us.
         $event->setResponse(new RedirectResponse($this->redirectDestination->get(), RedirectResponse::HTTP_SEE_OTHER));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = parent::build();
     $active_theme = $this->themeManager->getActiveTheme();
     $theme_name = $active_theme->getName();
     $destination = $this->redirectDestination->get();
     $visible_regions = $this->getVisibleRegionNames($theme_name);
     // Build an array of the region names in the right order.
     $build += array_fill_keys(array_keys($visible_regions), []);
     foreach ($visible_regions as $region => $region_name) {
         $query = ['region' => $region];
         if ($destination) {
             $query['destination'] = $destination;
         }
         $title = $this->t('<span class="visually-hidden">Place block in the %region region</span>', ['%region' => $region_name]);
         $operations['block_description'] = ['#type' => 'inline_template', '#template' => '<div class="block-place-region">{{ link }}</div>', '#context' => ['link' => Link::createFromRoute($title, 'block.admin_library', ['theme' => $theme_name], ['query' => $query, 'attributes' => ['title' => $title, 'class' => ['use-ajax', 'button', 'button--small'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]])]];
         $build[$region] = ['block_place_operations' => $operations] + $build[$region];
     }
     $build['#attached']['library'][] = 'block_place/drupal.block_place';
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function getOperations($plugin_id)
 {
     $payment_method_configuration_operations = $this->paymentMethodConfigurationListBuilder->getOperations($this->getPaymentMethodConfiguration($plugin_id));
     $titles = array('edit' => $this->t('Edit configuration'), 'delete' => $this->t('Delete configuration'), 'enable' => $this->t('Enable configuration'), 'disable' => $this->t('Disable configuration'));
     $operations = [];
     foreach ($payment_method_configuration_operations as $name => $payment_method_configuration_operation) {
         if (array_key_exists($name, $titles)) {
             $operations[$name] = $payment_method_configuration_operation;
             $operations[$name]['title'] = $titles[$name];
             $operations[$name]['query']['destination'] = $this->redirectDestination->get();
         }
     }
     return $operations;
 }
 /**
  * Shows a list of blocks that can be added to a theme's layout.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  * @param string $theme
  *   Theme key of the block list.
  *
  * @return array
  *   A render array as expected by the renderer.
  */
 public function listBlocks(Request $request, $theme)
 {
     // Since modals do not render any other part of the page, we need to render
     // them manually as part of this listing.
     if ($request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT) === 'drupal_modal') {
         $build['local_actions'] = $this->buildLocalActions();
     }
     $headers = [['data' => $this->t('Block')], ['data' => $this->t('Category')], ['data' => $this->t('Operations')]];
     // Only add blocks which work without any available context.
     $definitions = $this->blockManager->getDefinitionsForContexts($this->contextRepository->getAvailableContexts());
     // Order by category, and then by admin label.
     $definitions = $this->blockManager->getSortedDefinitions($definitions);
     $region = $request->query->get('region');
     $weight = $request->query->get('weight');
     $rows = [];
     foreach ($definitions as $plugin_id => $plugin_definition) {
         $row = [];
         $row['title']['data'] = ['#type' => 'inline_template', '#template' => '<div class="block-filter-text-source">{{ label }}</div>', '#context' => ['label' => $plugin_definition['admin_label']]];
         $row['category']['data'] = $plugin_definition['category'];
         $links['add'] = ['title' => $this->t('Place block'), 'url' => Url::fromRoute('block.admin_add', ['plugin_id' => $plugin_id, 'theme' => $theme]), 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 700])]];
         if ($region) {
             $links['add']['query']['region'] = $region;
         }
         if (isset($weight)) {
             $links['add']['query']['weight'] = $weight;
         }
         $destination = $this->redirectDestination->get();
         if ($destination) {
             $links['add']['query']['destination'] = $destination;
         }
         $row['operations']['data'] = ['#type' => 'operations', '#links' => $links];
         $rows[] = $row;
     }
     $build['#attached']['library'][] = 'block/drupal.block.admin';
     $build['filter'] = ['#type' => 'search', '#title' => $this->t('Filter'), '#title_display' => 'invisible', '#size' => 30, '#placeholder' => $this->t('Filter by block name'), '#attributes' => ['class' => ['block-filter-text'], 'data-element' => '.block-add-table', 'title' => $this->t('Enter a part of the block name to filter by.')]];
     $build['blocks'] = ['#type' => 'table', '#header' => $headers, '#rows' => $rows, '#empty' => $this->t('No blocks available.'), '#attributes' => ['class' => ['block-add-table']]];
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 protected function getDefaultOperations(EntityInterface $entity)
 {
     $destination = $this->redirectDestination->get();
     $operations = parent::getDefaultOperations($entity);
     foreach ($operations as &$operation) {
         $operation['query']['destination'] = $destination;
     }
     if ($entity->access('view')) {
         $operations['view'] = array('title' => $this->t('View'), 'weight' => -10, 'url' => $entity->urlInfo());
     }
     if ($entity->access('update_status')) {
         $operations['update_status'] = array('title' => $this->t('Update status'), 'attributes' => array('class' => array('use-ajax'), 'data-accepts' => 'application/vnd.drupal-modal'), 'query' => array('destination' => $destination), 'url' => $entity->urlInfo('update-status-form'));
     }
     if ($entity->access('capture')) {
         $operations['capture'] = array('title' => $this->t('Capture'), 'attributes' => array('class' => array('use-ajax'), 'data-accepts' => 'application/vnd.drupal-modal'), 'query' => array('destination' => $destination), 'url' => $entity->urlInfo('capture-form'));
     }
     if ($entity->access('refund')) {
         $operations['refund'] = array('title' => $this->t('Refund'), 'attributes' => array('class' => array('use-ajax'), 'data-accepts' => 'application/vnd.drupal-modal'), 'query' => array('destination' => $destination), 'url' => $entity->urlInfo('refund-form'));
     }
     if ($entity->access('complete')) {
         $operations['complete'] = array('title' => $this->t('Complete'), 'url' => $entity->urlInfo('complete'));
     }
     return $operations;
 }