You are here

function themekey_debug_set_debug_message in ThemeKey 7.2

Same name and namespace in other branches
  1. 7.3 themekey_debug.module \themekey_debug_set_debug_message()
  2. 7 themekey_debug.module \themekey_debug_set_debug_message()

Replacement for drupal_set_message() during ThemeKey's initialization. drupal_set_message() might inititialize the theme engine too early, which causes ThemeKey to not switch the theme.

themekey_debug_set_debug_message() put the untranslated messages on a stack and hand them over to drupal_set_message() on demand.

Parameters

$msg: the message as string. If the message is 'flush' all messages stored on the stack will be printed using drupal_set_message()

$placeholder: associative array of string replacments for $msg @see t()

$translate: boolean, if set to TRUE $msg will be handled by t() when handed over to drupal_set_message()

1 call to themekey_debug_set_debug_message()
themekey_set_debug_message in ./themekey.module
Replacement for drupal_set_message() during ThemeKey's initialization. drupal_set_message() might inititialize the theme engine too early, which causes ThemeKey to not switch the theme.

File

./themekey_debug.module, line 203
Provides a debug mode for module ThemeKey.

Code

function themekey_debug_set_debug_message($msg, $placeholder = array(), $translate = TRUE, $unshift = FALSE) {
  static $msg_stack = array();
  global $user, $theme;
  if (1 == $user->uid || user_access('themekey_debug_see_messages', $user) || variable_get('themekey_debug_non_admin_users', FALSE)) {
    if ('flush' == $msg) {
      $messages = array();
      if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
        $messages[] = t('Current theme: %theme', array(
          '%theme' => $theme,
        ));
      }
      foreach ($msg_stack as $key => $msg) {
        $messages[] = filter_xss($msg['translate'] ? t($msg['msg'], $msg['placeholder']) : $msg['msg'], array(
          'a',
          'b',
          'br',
          'li',
          'ul',
        ));
        unset($msg_stack[$key]);
      }
      if (!empty($messages)) {
        return theme('themekey_debug_messages', array(
          'messages' => $messages,
        ));
      }
    }
    else {
      $tmp = array(
        'msg' => $msg,
        'placeholder' => $placeholder,
        'translate' => $translate,
      );
      if ($unshift) {
        $tmp['msg'] = '<b>' . $tmp['msg'] . '</b>';
        array_unshift($msg_stack, $tmp);
      }
      else {
        $msg_stack[] = $tmp;
      }
    }
  }
}