In Drupal 7, I could use hook_admin_paths to decide if a page used the main or admin theme. This has changed in Drupal 8. This option is now set in a route definition. Existing routes, like node.add, can be altered. However, looking in node.routing.yml, under node.add, I do not see _admin_route: TRUE, which I intended to alter to FALSE.

What do I need to alter, and how, so that adding and editing nodes is done using the main theme?


You can configure this in UI, see the checkbox at the end of the theme list in /admin/appearance:

[x] Use the administration theme when editing or creating content

This config option is then used to alter the route in the following code example, which would also answer how to alter the route in a route subscriber:


  protected function alterRoutes(RouteCollection $collection) {
    if ($this->configFactory->get('node.settings')->get('use_admin_theme')) {
      foreach ($collection->all() as $route) {
        if ($route->hasOption('_node_operation_route')) {
          $route->setOption('_admin_route', TRUE);

More info https://www.drupal.org/docs/8/api/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones


Other alternative could be to use the Context module: there is an available Reaction called 'theme' that allows to set the theme depending on any available Condition (system path, content type, etc...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.