I am working with Drupal 8. I have enabled "Seven" as admin theme. When I have added an image with high resolution I am getting 2 error messages at a time(screenshot). I want to hide "green" colored status message from this particular page. I have tried with hook_page_attachments(array &$attachments) in my custom module to include the css for admin theme.

But it is not working. How to solve this issue?

enter image description here.


2 Answers 2


hook_page_attachments is not the correct hook. You want to implement hook_preprocess_HOOK, like the example below.

There are some caveats with this fix, especially if your site will be localized to other languages, see the comments within the code:

 * Implements hook_preprocess_HOOK().
 * Implements hook_preprocess_status_messages().
 * @param $variables
function mymodule_preprocess_status_messages(&$variables) {
  if (isset($variables['message_list']['status'])) {
    $status_messages = $variables['message_list']['status'];
    $dummy_message_parameter_1 = '_parameter_1_';
    $dummy_message_parameters =       [
      '%dimensions' => $dummy_message_parameter_1,
      '%new_width' => 0,
      '%new_height' => 0,
    // The message could change eventually, but it is unlikely.
    // This logic *could brake* in a some language translations, if the %dimensions string is not the first parameter.
    $file_resize_message = t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.', $dummy_message_parameters);
    // $file_resize_message_start is the part of the message that won't vary.
    $file_resize_message_start =strtok((string)$file_resize_message, $dummy_message_parameter_1); ;
    foreach ($status_messages as $delta => $message) {
      if (strpos((string)$message, $file_resize_message_start) !== FALSE) {
        // The next commented line still leaves a green area
        // unset($variables['message_list']['status'][$delta]);
        // Removing all messages, the side effect is that you could be
        // missing on some relevant messages

The message is set in the function file_validate_image_resolution at core/modules/file/file.module:447 (as of version 8.6.0-dev)

There is a good explanation about the hook implementation at Stack Overflow

  • It is working.Now the message is hidden.But the green section is still there.Is it possible to hide this?Thank you.
    – salu
    Sep 1, 2018 at 5:31
  • 1
    @salu – With CSS, yes.
    – leymannx
    Sep 1, 2018 at 6:27
  • @leymannx: I want to remove this from admin side.And my admin theme is "seven".So how can i add css?
    – salu
    Sep 1, 2018 at 12:38
  • @salu I just updated the code to remove all messages, I don't think would be easy use CSS here. The green area is innocuous, maybe consider leaving it. Sep 1, 2018 at 14:06

I'd fix this with CSS. But maybe this specific message can't be targeted specifically. Although I'd definitely try that first.

And then have a look at Disable Messages.

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.


  • 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.
  • I have already tried with this module.But it is not working
    – salu
    Sep 1, 2018 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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