Let’s explore more about the function drupal_set_message in Drupal. As a part of our Drupal Development Services, Bobcares offers solutions to your Drupal Queries.
Function “drupal_set_message” in Drupal
The database layer of Drupal does not abstract SQL functions across databases. To ensure portability across database engines, the code should only use ANSI-compliant functions supporting all the databases that Drupal supports. Additionally, Drupal core adds a few special functions that are exclusive to Drupal.
The drupal_set_message
function sets a message that the user will see. The $messages theme variable shows messages in the page template while storing them in a session variable. E.g.,
drupal_set_message(t(‘An error occurred and processing did not complete.’), ‘error’);
Function Parameters
1. string|\Drupal\Component\Render\MarkupInterface $message
: The translated message that the user will see. It should start with a capital letter and end with a period to be consistent with previous communications.
2. string $type
: It shows the type of the message. The supported values are ‘status’, ‘warning’, and ‘error’. The default value will be ‘status’.
3. bool $repeat
: The message will not repeat if this is FALSE and it is previously set. FALSE is the default.
Return Values Of The Function
The return will be array|null. A multidimensional array containing keys associating the set message kinds. The set messages for each type are stored in the indexed array values of each, and each message is an associative array with the formats, safe
and message
. safe
boolean shows whether the message string has been marked as safe. Unsafe strings will be automatically escaped. message
shows the message string.
Let’s look into an example:
The function returns NULL when we set no message.
[Are you looking for a different solution to your query? We are just a click away.]
Conclusion
To sum up, this article explains the function drupal_set_message in Drupal, along with an example.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments