@trigger_error('drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
$messenger = \Drupal::messenger();
if (isset($message)) {
$messenger->addMessage($message, $type, $repeat);
}
return $messenger->all();
}
```
This approach means that code can be refactored without breaking backwards-compatibility and, to upgrade any custom code to be compatible with Drupal 9, any references to `drupal_set_message()` just needed to be updated to use the new Messenger service.