0

I want to display the status messages to all of the users but the error and warnings to the administrator.I am using this code

<?php if($is_admin): ?>
      <?php print $messages; ?>
<?php endif; ?>

But I have no idea how to distinguish the message type.

2

This seems like a similar question to yours regarding printing messages. Additionally, this indicates that the message type is stored within the message object. You should just be able to iterate through a message object to get it. Something like

foreach (drupal_get_messages($messagesVariable) as $type => $messages) { 
    if (($status_heading[$type] != 'error') || ($status_heading[$type] != 'warning')) {
        *perform your given action here*
    }
}
  • it report the error Notice: Undefined variable: messagesVariable in ... – M a m a D Oct 22 '14 at 14:41
  • You need to define what messagesVariable is. – Nathan L. Oct 22 '14 at 14:44
  • it should be the $messages variable which is provided by drupal, I replaced it with that but didn't work – M a m a D Oct 22 '14 at 14:46
  • Read the first link I referenced. You're going to need a preprocessor function. I think you'll need to modify the answer slightly, putting the $variables['show_messages'] = FALSE in function YOURTHEME_preprocess_node(&$variables) and getting rid of the $variables['messages'] = theme('status_messages'); line and the entire preprocess_page function. – Nathan L. Oct 22 '14 at 14:57
1

Wouldn't the option to not display error messages in /admin/config/development/logging solve this problem?

"It is recommended that sites running on production environments do not display any errors."

Admins can still see the notices/warnings in the watchdog (Reports > Recent log messages). Although you should really fix those notices, since by default those messages get logged to the watchdog, which means reducing the site's performance by writing in a database table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.