You are here

function admin_theme_custom_theme in Administration theme 7

Implements hook_custom_theme().

File

./admin_theme.module, line 134
Enable the administration theme on more pages, then possible with Drupal's default administration page.

Code

function admin_theme_custom_theme() {
  $admin_theme_disallow = FALSE;
  $admin_theme = FALSE;

  // Check if some paths are disallow to get the theme.
  if (trim(variable_get('admin_theme_path_disallow', '')) != '') {

    // Pages that are defined by their normal path.
    $admin_theme_disallow = drupal_match_path($_GET['q'], variable_get('admin_theme_path_disallow', ''));

    // Pages that are defined with their alias.
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q']) {
      $admin_theme_disallow = $admin_theme || drupal_match_path($alias, variable_get('admin_theme_path_disallow', ''));
    }
  }

  // We should not show the admin theme if the user has no access,
  // or the path is in the disallow list.
  if (!user_access('access admin theme') || $admin_theme_disallow) {
    return;
  }

  // Check if an option is enabled and if it results to TRUE.
  $list = admin_theme_list();
  foreach ($list as $info) {
    $var = admin_theme_variable_name($info['module'], $info['option']);
    if ((bool) variable_get($var, '0') && module_invoke($info['module'], 'admin_theme_check', $info['option'])) {
      $admin_theme = TRUE;
    }
  }

  // Some custom defined pages should get admin theme.
  if (trim(variable_get('admin_theme_path', '')) != '') {

    // Pages that are defined by their normal path.
    $admin_theme = $admin_theme || drupal_match_path($_GET['q'], variable_get('admin_theme_path', ''));

    // Pages that are defined with their alias.
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q']) {
      $admin_theme = $admin_theme || drupal_match_path($alias, variable_get('admin_theme_path', ''));
    }
  }

  // Use the admin theme for the current request (if global admin theme setting is checked).
  if ($admin_theme) {
    return variable_get('admin_theme');
  }
  return;
}