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 ..
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.
}
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.
I'm not exactly sure what your ultimate goal is either. More explanation?
If you're checking for the path, Scott Reynen's #1 should do the trick.
Drupal 6 also has a default variable, $is_admin. This will be TRUE if the current user has admin access. Checking for this variable might be helpful. For more info, see here: http://api.drupal.org/api/drupal/modules--system--page.tpl.php/6
To your follow-up question, the front end theme is ALWAYS displayed in admin/build/block. This is correct and expected behavior, since while you're moving blocks around and assigning them to theme sections, you'd want to know where they're going in the theme you are configuring. If you have multiple themes enabled, try click on a different theme's settings (secondary row) while at admin/build/block. You'll see what I mean.
For the first question the above solutions must do....coming to the second one,it seems that you want to add the login block to the center (ie;the main content ) of the page and that too only on some pages..if this is the case you need to go to the blocks config page and set the "User Login" block to the desired place on the page and click save. Then again click configure next to the block and you will get the options to configure the settings like "on which pages this block must be shown"..etc..etc..
For Drupal 6: @timmy and @Scott Reynen -- arg(0) and substr($_GET['q'], 0, 5) equals 'admin' will miss some patterns. The code below gets all the Admin page urls on my site, your site may have more or less.
$arg = arg();
$isAdminPage = ($arg[0] == 'admin' || $arg[2] == 'edit' || $arg[0] == 'user' || $arg[2] == 'workflow' || $arg[2] == 'statistics');
if ($isAdminPage) {
// do admin stuff
}
© 2022 - 2024 — McMap. All rights reserved.