1

I know that custom theme usually inherited from the "stable" theme, and the default backend theme is "seven. I like the UI of "/user/login","/user/register" and "/forum" pages. If I use a custom theme inherited from "stable", how can I make the UI apperance of these special pages stay in "seven" theme? I tried to set the "base theme" to "classy" or "false", but the theme suggestions still choose the "stable" as a default.

2 Answers 2

1

How can I make the UI appearance of these special pages stay in "seven" theme?

Seven is the default theme for admin paths in Drupal. To mark special pages like the user login as admin path use the module Admin Login Path.

You can add your own paths in a custom route subscriber like the one from the module:

<?php

namespace Drupal\admin_login_path\Routing;

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

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Define the routes we want to use the admin theme.
    $login_routes = ['user.login', 'user.register', 'user.pass'];
    foreach ($collection->all() as $name => $route) {
      if (in_array($name, $login_routes)) {
        $route->setOption('_admin_route', TRUE);
      }
    }
  }

}
5
  • Thank you for your so quick answer. This module works perfect for the path like 'user/login' and 'user/register' of user module. But it seems have no effect on the path of '/forum', is there any solution for that?
    – xibinke
    Commented Dec 30, 2018 at 3:15
  • See the second part of the answer. Copy the code to your custom module and modify the path list.
    – 4uk4
    Commented Dec 30, 2018 at 9:14
  • I did add 'forum' to the $login_routes parameter in modules/admin_login_path/src/Routing/RouteSubscriber.php, but it has no effect.
    – xibinke
    Commented Dec 30, 2018 at 9:42
  • You have to add the route name forum.index. Install Devel and go to /devel/routes to see all routes.
    – 4uk4
    Commented Dec 30, 2018 at 9:49
  • That's really wonderful! Yes, all the path can run under the backend theme now, Thank you.
    – xibinke
    Commented Dec 31, 2018 at 3:09
0

Just for completeness: there are modules for D8 that allow you more control over which theme to use on which pages:

In D7 the most popular is ThemeKey.

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.