Which Hook should I use to simply print a message if a configuration is not done yet?
The only idea i've got was hook_node_view, but maybe someone knows something better ?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Traditionally that's what
hook_requirements() is for
Check installation requirements and do status reporting.
It hooks your module into the status report at /admin/reports/status.
Drupal doesn't have a mechanism for displaying messages in response to a requirement failure; so if you need to show something to the user,
hook_node_view() makes as much sense as anything else IMO.
Actually that's not strictly true (I didn't read the docs properly)...
hook_requirements() does already handle that in one way or another. From the docs relating to the 'runtime' phase:
any requirement with a severity of REQUIREMENT_ERROR severity will result in a notice on the administration configuration page.
So if your users have access to the admin config page you can use this hook to automatically display them a message. But if the message needs to be on a different page, you'll have to take a different route with the advice in @FreeRadical's answer.
If you want to check installation requirements and report on any failures during installation or any of the other phases where it is applicable, it is
hook_requirements() - already adequately covered by Clive.
But if you just want to print a warning message to the user/admin about some tasks (such as setting some variables), e.g.:
drupal_set_message(t('You've selected X and Y. These are mutually exclusive.'), 'warning');
... you can call this function from more or less anywhere inside one of the functions in your module where you do some check and want to output a warning because the check indicates that something should be done before proceeding. It doesn't have to be a hook. But obviously the function containing the call need to be executed for the message to show. However, placing it inside the same function as the function that performs the check usually takes care of that.
For instance, if the message is used to tell the admin that his choces are mutually exclusive, I have it inside settings submit handler (e.g.
MYMODULE_admin_settings_submit). since I usually do this type of sanity checks in the submit handler.
drupal_set_message() just appends the message to an array that is shown on the next page load.