Some time I need to use a shutdown function. Here is a stupid example:
...
drupal_register_shutdown_function('display_message');
...
function display_message() {
Drupal::messenger()->addMessage('Hello world');
}
Is it possible to display this message as for now, it is not working (even at the nex page refresh)?
As requested I will explain why I need to use shutdown function.
My use case:
We are in the presave hook of node A which just got a new custom status (which needs to be saved), let say status 5.
When this kind of node reach status 5, I need to save/update another node B which contains a reference to node A.
In the presave hook of node B, calculations are made using the value of this status... this means the status of node A must be saved before starting the calculations.
This is why I am postponing the saving of node B with a shutdown function but all the end user messages are not displayed.
You can argue that in the presave hook of node A, I can call a function with the status and the node A as parameter which will do the job; but there are many exchanges/references like this one and to avoid a spaghetti code, I put all my business model code in the presave functions of those two kinds of nodes.