1

Is there a way of suppressing a particular class of messages from being displayed on the screen, such as the one displayed below?

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; GeSHi has a deprecated constructor in require_once() (line 837 of {site_root}/sites/all/modules/libraries/libraries.module)

It comes up all the time and it belongs to the php and severity debug class of error messages.

I don't want to turn off the display of messages on the screen, just a particular class of message which come so often they are a nuisance.

It is possible to toggle their display on and off when required but still log them to the database?

1

You can use Disable Messages or look how they do it. Among other features you'll get a permission to specifically hide all messages of a given type from any role.

Gives a site owner options to disable specific messages shown to end users. The core drupal message system as offered by drupal_set_message is an excellent way for modules to send out messages to the end users. However not all drupal site owners are keen to show all the messages sent out by drupal core and all modules to their users. This module gives site administrators a reasonably powerful way to filter out messages shown to the end users.

Features

  • Filter out messages that match a full text string exactly.
  • Filter out messages that match a regular expression.
  • Permissions to specifically hide all messages of a given type from any role.
  • Disable all filtering for specific users.
  • Disable all filtering for specific paths.
  • Apply filtering only for specific paths.
  • Debug system to get messages in the HTML without showing it to the end users.

Apart from that I found this little gem:

function MYMODULE_preprocess_status_messages(&$variables) {

  // The exact message you want to filter.
  $message = 'Further instructions have been sent to your e-mail address.';

  if (isset($_SESSION['messages'])) {
    foreach ($_SESSION['messages'] as $type => $messages) {

      // Limit it to a certain type if you want to.
      if ($type == 'status') {

        $pos = array_search($message, $messages);

        if ($pos !== FALSE) {
          unset($_SESSION['messages'][$type][$pos]);
        }
      }
    }
  }
}

Source: https://api.drupal.org/comment/51793#comment-51793


Here's another alternative to filter all messages of a certain type.

/**
 * Implements hook_page_build().
 */
function MYMODULE_page_build(&$page) {

  $hide_types = ['status', 'error', 'warning'];

  if (isset($_SESSION['messages'])) {
    foreach ($_SESSION['messages'] as $type => $messages) {
      if (in_array($type, $hide_types)) {
        unset($_SESSION['messages'][$type]);
      }
    }
  }
}

You could also easily get the $account = global $user and check its roles to tighten this request if you need.


Last but not least – not recommended - you can remove or if-wrap the <?php print $messages; ?> variable in your theme's page.tpl.php. But editing templates for this kind of logic should be considered bad practice.

|improve this answer|||||
  • I have this module on my system, but it seems to be applied to end users only,but not for the administrator, which is what I am really looking for. – vfclists Aug 16 '18 at 11:46
  • @vfclists – Permissions are set role-wise. Isn't this sufficient? – leymannx Aug 16 '18 at 12:02
  • I will look into that – vfclists Aug 16 '18 at 12:04
  • @vfclists – Added some snippets to be used in a custom module. Placing them into your theme's template.php might work as well. – leymannx Aug 16 '18 at 12:21

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.