Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if the user is in the admin part of drupal?

How do i check if the current page is in the admin section of drupal?. I want to display a login form in some pages from the main menu but the login page is displayed in the block selection menu .Please suggest a solution ..

like image 958
Sreejith Sasidharan Avatar asked Dec 19 '10 13:12

Sreejith Sasidharan


2 Answers

For Drupal 7 you can use path_is_admin() .

if (path_is_admin(current_path())) {
  // Do stuff.
}

For Drupal 8 isAdminRoute()

$is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
if ($is_admin) {
  // Do stuff.
}
like image 99
gagarine Avatar answered Oct 19 '22 04:10

gagarine


I don't fully understand your end goal, but here are two answers to your question:

1) if (arg(0) == 'admin') { ... } will indicate if someone is in the admin section, since the entire admin section has paths prefixed with admin/

2) At admin/settings/admin/theme you can select a separate theme for the admin section, and then you'll know someone is in admin when that theme is loading rather than the main theme.

like image 20
Scott Reynen Avatar answered Oct 19 '22 04:10

Scott Reynen