Admin theme not active when using batch export method and a display path starting with admin/

Created on 23 June 2023, over 1 year ago
Updated 15 May 2024, 6 months ago

Problem/Motivation

When using the batch export method in combination with a path that starts with admin/ it is expected that the admin theme would be active and used for the batch export.

Currently the batch will use the default theme instead of the admin theme, as neither Drupal\views_data_export\Plugin\views\display\DataExport::collectRoutes (via parent Drupal\rest\Plugin\views\display\RestExport::collectRoutes) nor Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes set the route option _admin_route - which is used to determine the active theme.

Steps to reproduce

I have only tested this with 9.5

  1. Install Drupal using core profile
  2. Enable views_data_export
  3. Add a Data Export display to the content view, use Method: Batch under export settings and use admin/content/export (or any path beginning with admin) as the path.
  4. Visit /admin/content/export
  5. Observe the batch process is using the site theme, not the admin theme

From debugging we can see

When the routes are built:

  1. Drupal\rest\Plugin\views\display\RestExport::collectRoutes returns the route object with _format set to the export format selected in "Accepted request formats" in the view (e.g csv)
  2. AdminRouteSubscriber::isHtmlRoute returns FALSE and so does not mark this as an admin route - it does this by checking the _format requirement of the route to see if it has the html format. In this case, the format is csv as so it does not get marked as an admin route

When the request is handled:

  1. \Drupal\user\Theme\AdminNegotiator does not apply as the Drupal\Core\Routing\AdminContext::isAdminRoute returns FALSE for the route
  2. DataExport::buildBatch calls batch_process which calls \Drupal::theme()->getActiveTheme()->getName() to set the theme for the batch - which is not the admin theme due to the above conditions.

Proposed resolution

I believe if batch it in use, it is expected behaviour that using an admin path /admin should use the admin theme.

This would involve the DataExport plugin overriding the collectRoutes method to mark the route as an admin route if the batch export method is used and the path starts with admin.

Remaining tasks

  1. Agree on approach
  2. Patch
  3. Review

User interface changes

TBC

API changes

TBC

Data model changes

TBC

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇳🇿New Zealand ericgsmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024