--- includes/bootstrap.inc Sun Nov 02 10:56:35 2008 +++ includes/bootstrap.inc Wed Nov 05 17:33:41 2008 @@ -921,7 +921,7 @@ * @param $message * The message should begin with a capital letter and always ends with a * period '.'. - * @param $type + * @param $severity * The type of the message. One of the following values are possible: * - 'status' * - 'warning' @@ -929,19 +929,29 @@ * @param $repeat * If this is FALSE and the message is already set, then the message won't * be repeated. + * @param $type + * (optional) The message type. */ -function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) { + function drupal_set_message($message = NULL, $severity = 'status', $repeat = TRUE, $type = NULL) { if ($message) { if (!isset($_SESSION['messages'])) { $_SESSION['messages'] = array(); } - if (!isset($_SESSION['messages'][$type])) { - $_SESSION['messages'][$type] = array(); + if (!isset($_SESSION['messages'][$severity])) { + $_SESSION['messages'][$severity] = array(); + } + + if (!isset($_SESSION['messages'][$severity][$type])) { + $_SESSION['messages'][$severity][$type] = array(); } - if ($repeat || !in_array($message, $_SESSION['messages'][$type])) { - $_SESSION['messages'][$type][] = $message; + if ($repeat || !in_array($message, $_SESSION['messages'][$severity]) || !in_array($message, $_SESSION['messages'][$severity][$type])) { + if ($type) { + $_SESSION['messages'][$severity][$type][] = $message; + } else { + $_SESSION['messages'][$severity][] = $message; + } } } @@ -952,26 +962,66 @@ /** * Return all messages that have been set. * - * @param $type - * (optional) Only return messages of this type. + * @param $severity + * (optional) Only return messages of this severity level. Has three default + * values: + * - 'status' + * - 'warning' + * - 'error' * @param $clear_queue * (optional) Set to FALSE if you do not want to clear the messages queue + * @param $type + * (optional) Restrict returned values to a specific type. * @return * An associative array, the key is the message type, the value an array * of messages. If the $type parameter is passed, you get only that type, * or an empty array if there are no such messages. If $type is not passed, - * all message types are returned, or an empty array if none exist. + * all messages are returned, or an empty array if none exist. */ -function drupal_get_messages($type = NULL, $clear_queue = TRUE) { +function drupal_get_messages($severity = NULL, $clear_queue = TRUE, $type = NULL) { if ($messages = drupal_set_message()) { - if ($type) { - if ($clear_queue) { - unset($_SESSION['messages'][$type]); + + if ($severity) { + + if ($type) { + + if ($clear_queue) { + unset($_SESSION['messages'][$severity][$type]); + } + if (isset($messages[$severity][$type])) { + return array( + $severity => $messages[$severity][$type], + ); + } + } + + else { + + if ($clear_queue) { + unset($_SESSION['messages'][$severity]); + } + if (isset($messages[$severity])) { + return array( + $severity => $messages[$severity], + ); + } } - if (isset($messages[$type])) { - return array($type => $messages[$type]); + + } + + elseif ($type) { + $output = array(); + foreach ($messages as $severity => $data) { + if (isset($messages[$severity][$type])) { + if ($clear_queue) { + unset($_SESSION['messages'][$severity][$type]); + } + $output[$severity] = $messages[$severity][$type]; + } } + return $output; } + else { if ($clear_queue) { unset($_SESSION['messages']); @@ -979,6 +1029,7 @@ return $messages; } } + return array(); }