You are here

function themekey_check_theme_enabled in ThemeKey 7.3

Same name and namespace in other branches
  1. 6.4 themekey_base.inc \themekey_check_theme_enabled()
  2. 6.2 themekey_base.inc \themekey_check_theme_enabled()
  3. 6.3 themekey_base.inc \themekey_check_theme_enabled()
  4. 7 themekey_base.inc \themekey_check_theme_enabled()
  5. 7.2 themekey_base.inc \themekey_check_theme_enabled()

Checks if a theme is enabled and fires warning messages to the site's administrator

This function has been moved from themekey_base.inc to themekey.module because it's required by themekey_ajax_base_page_theme() which is used as menu callback. See https://drupal.org/node/2265813

Parameters

$theme: name of the theme as string

$settings_page: boolean that indicates if the function is called from ThemeKey's administration backend which causes a different message

Return value

TRUE if the theme is enabled, otherwise FALSE

6 calls to themekey_check_theme_enabled()
themekey_ajax_base_page_theme in ./themekey.module
Wrapper for ajax_base_page_theme() that optionally skips the token check.
themekey_custom_theme in ./themekey.module
Implements hook_custom_theme().
themekey_ui_author2theme in ./themekey_ui.module
This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
themekey_ui_nid2theme in ./themekey_ui.module
This function implements the interface of a ThemeKey mapping function, but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
themekey_ui_node_author2theme in ./themekey_ui.module
This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.

... See full list

2 string references to 'themekey_check_theme_enabled'
themekey_match_rules in ./themekey_base.inc
This function steps through the rule chain and returns a theme.
themekey_rule_chain_form_validate in ./themekey_admin.inc
Validation of

File

./themekey.module, line 290
ThemeKey is designed as a generic theme-switching module.

Code

function themekey_check_theme_enabled($theme, $settings_page = FALSE) {
  static $themes_enabled = array();
  static $warned = FALSE;
  static $displayed_error = FALSE;
  if (!$theme || 'default' == $theme) {
    return TRUE;
  }
  if (empty($themes_enabled)) {
    if ($result = db_select('system', 's')
      ->fields('s', array(
      'name',
    ))
      ->condition('type', 'theme')
      ->condition('status', '1')
      ->execute()) {
      foreach ($result as $row) {
        $themes_enabled[] = $row->name;
      }
    }
  }
  if (in_array($theme, $themes_enabled)) {
    return TRUE;
  }
  elseif ('ThemeKeyAdminTheme' == $theme && variable_get('admin_theme', '0') && in_array(variable_get('admin_theme', '0'), $themes_enabled)) {
    return TRUE;
  }
  if ($settings_page) {
    if (!$displayed_error) {
      drupal_set_message(filter_xss(t("Your current configuration of theme rules uses at least one theme that is not enabled. Nevertheless, this configuration is stored, but affected rules won't be applied until the targeted theme is enabled at !build_themes.", array(
        '!build_themes' => l(t('!path', array(
          '!path' => 'admin/appearance',
        )), 'admin/appearance'),
      ))), 'error');
      $displayed_error = TRUE;
    }
  }
  else {
    if (!$warned && variable_get('themekey_debug_trace_rule_switching', FALSE)) {

      // Don't use the l() function at this early stage of bootstrapping because it will initialize the theme engine. Use url() instead.
      themekey_set_debug_message('A matching Theme Switching Rule to select theme %theme was not applied because this theme is disabled. You can enable this theme at !build_themes, remove this Theme Switching Rule at !themekey_properties, or edit the current node if the theme was selected using ThemeKey UI.', array(
        '%theme' => $theme,
        '!build_themes' => '<a href="' . url('admin/appearance') . '">admin/appearance</a>',
        '!themekey_properties' => '<a href="' . url('admin/config/user-interface/themekey/properties') . '">admin/config/user-interface/themekey/properties</a>',
      ));
      $warned = TRUE;
    }
  }
  return FALSE;
}