Commit fcafcfea authored by Steven Jones's avatar Steven Jones Committed by Steven Jones
Browse files

Issue #3368855 by steven jones: Set the admin path option on routes.

parent 1fc25893
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@
  "type": "drupal-module",
  "license": "GPL-2.0-or-later",
  "require": {
    "drupal/csv_serialization": "~1.4 || ~2.0 || ~3 || ~4"
    "drupal/csv_serialization": "~1.4 || ~2.0 || ~3 || ~4",
    "php": ">=8.0"
  },
  "require-dev": {
    "drupal/search_api": "~1.12",
+9 −24
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ use Drupal\views\Views;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Symfony\Component\Routing\RouteCollection;

/**
 * Provides a data export display plugin.
@@ -38,26 +37,6 @@ use Symfony\Component\Routing\RouteCollection;
 */
class DataExport extends RestExport {

  /**
   * {@inheritdoc}
   */
  public function collectRoutes(RouteCollection $collection) {
    parent::collectRoutes($collection);

    // \Drupal\system\EventSubscriber\AdminRouteSubscriber will not apply the
    // _admin_route to the view as the route is not an HTML route - but the
    // batch should pick up the admin theme for this route if it begins with
    // /admin.
    if ($this->getOption('export_method') === 'batch' && str_starts_with($this->getOption('path') ?? '', 'admin/')) {
      $view_id = $this->view->storage->id();
      $display_id = $this->display['id'];

      if ($route = $collection->get("view.$view_id.$display_id")) {
        $route->setOption('_admin_route', TRUE);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
@@ -954,13 +933,19 @@ class DataExport extends RestExport {
   */
  protected function getRoute($view_id, $display_id) {
    $route = parent::getRoute($view_id, $display_id);
    $view = Views::getView($view_id);
    $view->setDisplay($display_id);

    // If this display is going to perform a redirect to the batch url
    // make sure thr redirect response is never cached.
    if ($view->display_handler->getOption('export_method') == 'batch') {
    if ($this->getOption('export_method') == 'batch') {
      $route->setOption('no_cache', TRUE);

      // Additionally if the path is an admin path we need to set the
      // _admin_route option to TRUE so the batch process is executed in the
      // same theme as we'd normally expect for the path even though this is
      // not an HTML route.
      if (str_starts_with($this->getOption('path') ?? '', 'admin/')) {
        $route->setOption('_admin_route', TRUE);
      }
    }
    return $route;
  }