logo

Print Status or Error Message in Drupal 9

21
October

Print Status or Error Message in Drupal 9
By: Anonymous | Published On: Thu, 10/21/2021 - 20:36

Print message in Drupal 8, We use following method in Drupal 8 to print message but this code is not work in Drupal 8.

    drupal_set_message('Hello world');
    drupal_set_message('Hello world', 'error');
    drupal_set_message('Hello world', 'status');
    drupal_set_message('Hello world', 'warning');
	

Print message in Drupal 9. Following syntax can use to print message in custom code, Error Message, Status Message, Waring Message

    $this->messenger()->addMessage('Hello world');
    $this->messenger()->addError('Hello world');
    $this->messenger()->addStatus('Hello world');
    $this->messenger()->addWarning('Hello world');
	

Need Help ?