8

I want the administration theme for all the default pages, except one: /user/%/edit

How do I get the default theme to display for this page instead of the administration theme?

4 Answers 4

13

For Drupal 7 you can use Administration theme or hook_admin_paths_alter() in your custom module.

/**
 * Implements hook_admin_paths_alter().
 */
function my_module_admin_paths_alter(&$paths) {
  $paths['user/*/edit'] = FALSE;
}

For Drupal 8, see https://www.drupal.org/node/2224207.

0
1

I believe ThemeKey allows you to control that: https://drupal.org/project/themekey

If that doesn't work, you can force a specific theme for a page using: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_custom_theme/7

0

For anyone looking for a D8 solution:

Filename: YOUR_MODULE.routing.yml

YOUR_MODULE.user_edit:
  path: '/user/{user}/edit'
  defaults:
    _entity_form: 'user.default'
    _title_callback: 'Drupal\user\Controller\UserController::userTitle'
  requirements:
    _entity_access: user.update
    user: \d+
  options:
    _admin_route: FALSE
4
  • It's better to alter the routes with route subscriber rather than defining a new one, like so: drupal.stackexchange.com/a/85675/14665 but setOptions needs to be used in this specific case.
    – David
    Commented Apr 21, 2021 at 7:05
  • Thanks for your feedback I would be interested in why it's better. If you could provide an answer with that approach, that would be amazing!
    – ipwa
    Commented Apr 21, 2021 at 7:25
  • Because that's the correct way of altering existing routes. I'll provide exact solution ijn a separate answer.
    – David
    Commented Apr 21, 2021 at 7:26
  • Sounds good, I think my answers works well for beginner because it is super simple to implement. Looking forward to your approach altering the existing route instead of defining a new one that overrides the core route.
    – ipwa
    Commented Apr 21, 2021 at 7:54
0

In Drupal 10, I managed to disable the admin theme for the user/{user}/edit page, as follows:

  1. Create a custom route subscriber in your custom module.

With the following code:

<?php    

namespace Drupal\your_module\EventSubscriber;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Route subscriber.
 */
final class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {

    // Disables the admin theme for user edit page.
    if ($route = $collection->get('entity.user.edit_form')) {
      $route->setOption('_admin_route', FALSE);
    }
  }

}
  1. Create or edit the your_module.services.yml file in order to register the route subscriber.

    services:
      your_module.route_subscriber:
        class: Drupal\your_module\EventSubscriber\RouteSubscriber
        tags:
          - { name: event_subscriber }
    

As an alternative you can also patch the core file web/core/modules/user/src/Entity/UserRouteProvider.php or use contrib module to switch theme. See this comment on drupal.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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