drupal 8 how to modify status messages
/**
* Implements hook_preprocess_HOOK().
*
* @param $variables
*/
function mymodule_preprocess_status_messages(&$variables) {
if(isset($variables['message_list']['status'])){
$status_messages = $variables['message_list']['status'];
foreach($status_messages as $delta => $message) {
if (strpos((string) $message, 'The message that I am expecting') !== FALSE) {
$variables['message_list']['status'][$delta] = "Some different message text";
}
}
}
}