Answers for "drupal 8 how to modify status messages"

0

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";
      }
    }
  }
}
Posted by: Guest on July-13-2021

Browse Popular Code Answers by Language