We like to share the status messages in multiple location in single request, so we retrieve them:
function get_messages(){
$status_messages = array();
//loop through each message type
foreach (drupal_get_messages(null, false) as $type => $messages) {
foreach($messages as $key => $message){
$status_messages[$type]['enabled'] = true;
$status_messages[$type]['messages'] = array(
'message' => $message
);
}
}
return $status_messages;
}
Here, since we are passing "FALSE" to the drupal_get_messages function the messages are not reset which is what we like because multiple locations gets to call this function, however. At some point, the messages need to be reset.
One option is to clear messages at the last point of the request. Where and how to do that?
Another option, would implement a cache and run drupal_get_messages() with "TRUE" to call once and reset at the same time. I am not familiar with cache in Drupal or PHP. How to do that?
In short, we like to access status messages in multiple locations and $variable['messages'] is not available to serve the purpose. How to do that? Thank You for help