Boy Baukema

Boy Baukema
15 april 2016

Do you want your websites users to log in? For certain types you would, but often there is no need. The Ibuildings website does not allow you to register an account and log in. Why would it?

However by default Drupal 8 (and earlier) considers logging in on /user part of the frontend theme. This means that either you have to theme it or accept a horribly broken login page.

Or you could convince Drupal to apply the admin theme to user pages.

In Drupal 7 you can use the example given on the page for hook_admin_paths_alter().

In Drupal 8 you’ll need to implement a custom RouteSubscriber. Here is what we have done for our new Drupal 8 site:

 $route) {
      if (strpos($route_name, 'user.') !== 0) {
      $route->setOption('_admin_route', TRUE);

Next you need to register it as a service and tag it with “event_subscriber” ​*in*​ your services.yml:

    class: Drupal\ib_core\Routing\RouteSubscriber
     - { name: event_subscriber }

Finally you’ll need to allow anonymous users to view the administration theme on “/admin/people/permissions”.

Hope this helps!