drupal 8 add message

To add a message in Drupal 8, you can use the drupal_set_message() function. This function allows you to display a message to the user. Here's an example of how to use it:

drupal_set_message('This is a sample message');

You can also specify the type of message by passing a second argument to the function. The available types are 'status', 'warning', and 'error'. Here's an example:

drupal_set_message('This is a status message', 'status');
drupal_set_message('This is a warning message', 'warning');
drupal_set_message('This is an error message', 'error');

These messages will be displayed to the user on the next page load. You can add them in your custom module or theme files to provide feedback or notifications to the user.