Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need to add 'Error:' prefix to every error message (not prefix on the field name but on the whole message).
I do it like this:
function theme_status_messages($variables) {
$display = $variables ['display'];
$output = '';
$status_heading = array(
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
);
foreach (drupal_get_messages($display) as $type => $messages) {
$myprefix = $type == 'error' ? 'ERROR: ' : '';
$output .= "<div class=\"messages $type\">\n";
if (!empty($status_heading [$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading [$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $myprefix . $message . "</li>\n";
}
$output .= " </ul>\n";
}
else {
$output .= $myprefix . reset($messages);
}
$output .= "</div>\n";
}
return $output;
}
but this is only working with Drupal default messages.
Can someone help me with this?