Prevent the user profile from being displayed in backend theme using RouteSubscriber
Authenticated users should never see the admin/backend theme in your websystem
<?php
namespace Drupal\scp_base\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Make sure profile pages are not admin pages, in order to load the right
// translation.
if ($route = $collection->get('profile.user_page.single')) {
$route->setOption('_admin_route', FALSE);
}
}
}
Issue:
Authenticated users should never see the admin/backend theme in your websystem
Prerequisites:
You need to have the profile module installed in your project.
Solution:
Paste the provided code snippet into your RouteSubscriber.php file.
Ihre Drupal-Website zukunftssicher machen
Wir prüfen Ihr System und zeigen, was Sie für AI, Wartung und Upgrades brauchen.