--- C:/projects/d7/includes/bootstrap.inc Mon Sep 29 15:17:48 2008 +++ C:/projects/d7/includes/bootstrap.new.inc Mon Sep 29 17:50:44 2008 @@ -849,8 +849,13 @@ * @param $repeat * If this is FALSE and the message is already set, then the message won't * be repeated. + * @param $module + * The module presenting the message. + * @param $mid + * The id of a message should be a string, does not have to be unique. + * For example, it might be the form id of messages set with form_set_error(). */ -function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) { + function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE, $module = NULL, $mid = NULL) { if ($message) { if (!isset($_SESSION['messages'])) { $_SESSION['messages'] = array(); @@ -859,9 +864,25 @@ if (!isset($_SESSION['messages'][$type])) { $_SESSION['messages'][$type] = array(); } + + if (!isset($_SESSION['messages'][$type][$module])) { + $_SESSION['messages'][$type][$module] = array(); + } - if ($repeat || !in_array($message, $_SESSION['messages'][$type])) { - $_SESSION['messages'][$type][] = $message; + if ($repeat || !in_array($message, $_SESSION['messages'][$type]) || !in_array($message, $_SESSION['messages'][$type][$module])) { + if ($module) { + if ($mid) { + $_SESSION['messages'][$type][$module][$mid][] = $message; + } else { + $_SESSION['messages'][$type][$module][] = $message; + } + } else { + if ($mid) { + $_SESSION['messages'][$type][$mid][] = $message; + } else { + $_SESSION['messages'][$type][] = $message; + } + } } } @@ -873,32 +894,113 @@ * Return all messages that have been set. * * @param $type - * (optional) Only return messages of this type. + * (optional) Only return messages of this type. Has multiple options + * depending on context (see the $context parameter below) Can be either a + * string representing the message type (default behaviour), a string + * representing the message ID or an array of module names in this format: + * $type = array('user' => 'user', 'comment' => 'comment'); * @param $clear_queue * (optional) Set to FALSE if you do not want to clear the messages queue + * @param $context + * (optional) Set the context of type. Permitted values are: + * - 'normal' ($type expects original behaviour, a standard Drupal message type) + * - 'mid' ($type expects message id of a set of messages) + * - 'modules' ($type expects an array of module names) * @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. + * or an empty array if there are no such messages. The return array structure + * varies depending on the $context parameter. Possibilities are: + * - $content = 'normal' + * Array ( + * type => Array ( + * Message 1 + * Message 2 + * ) + * ) + * - $content = 'mid' + * Array ( + * message_id => Array ( + * Message 1 + * Message 2 + * ) + * ) + * - $content = 'modules' + * Array ( + * type => Array ( + * module_name => Array ( + * Message 1 + * Message 2 + * ) + * ) + * ) + * If $type is not passed, all messages are returned, or an empty array if + * none exist. */ -function drupal_get_messages($type = NULL, $clear_queue = TRUE) { +function drupal_get_messages($type = NULL, $clear_queue = TRUE, $context = 'normal') { if ($messages = drupal_set_message()) { + if ($type) { - if ($clear_queue) { - unset($_SESSION['messages'][$type]); - } - if (isset($messages[$type])) { - return array($type => $messages[$type]); + + switch ($context) { + case 'modules': + if (is_array($type)) { + foreach ($type as $module) { + foreach ($messages as $messagetype => $message) { + if ($clear_queue) { + unset($_SESSION['messages'][$messagetype][$module]); + } + if (isset($messages[$messagetype][$module])) { + $output = array( + $messagetype => array( + $module => $messages[$messagetype][$module] + ), + ); + } + } + } + } + return $output; + + case 'mid': + foreach ($messages as $messagetype => $data) { + foreach ($data as $module => $moduledata) { + if (isset($messages[$messagetype][$module][$type])) { + if ($clear_queue) { + unset($_SESSION['messages'][$messagetype][$module][$type]); + } + $output[$messagetype][$type] = $messages[$messagetype][$module][$type]; + } + } + if (isset($messages[$messagetype][$type])) { + if ($clear_queue) { + unset($_SESSION['messages'][$messagetype][$type]); + } + $output[$messagetype][$type] = $messages[$messagetype][$type]; + } + } + return $output; + + case 'normal': + if ($clear_queue) { + unset($_SESSION['messages'][$type]); + } + if (isset($messages[$type])) { + return array( + $type => $messages[$type], + ); + } } - } - else { + + + } else { if ($clear_queue) { unset($_SESSION['messages']); } return $messages; } } + return array(); }