4

By default, Drupal prints out a notification message that images exceeding the maximum dimensions were resized. I want to disable this message.

The relevant line is located in file_validate_image_resolution():

  drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));

Obviously, the quick way to do this is to put two little slashes right before the line. But I am trying to do this without hacking core. I copied the entire function into MYMODULE_file_validate_image_resolution(), then commented the lines out, but this had no effect. What's the right way to do this?

6
+50

Disable Messages module helps you to disable any type of message in drupal.

It module has following 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.

Once you install the module you can see the configuration options at admin/config/development/disable-messages.

For your requirement just enter following text in "Messages to be disabled:" textarea.

The image was resized to fit within the maximum allowed dimensions of .*? pixels.

enter image description here

Note : Make sure necessary permission to be set like below.

enter image description here

0

1) You can remove the message in hook_file_validate, hook_theme_registry_alter or on page load:

  $message = t('YOUR MESSAGE');
  foreach ($_SESSION['messages']['status'] as $status => $statusmessage) {
    if ($message == $statusmessage) {
      unset($_SESSION['messages']['status'][$status]);
    }
  }

2) You can try to replace core validator of your image field widget with a custom one in #upload_validators using hook_field_widget_form_alter.

3) You can remove file_validate_image_resolution from #upload_validators and do your validation without message in hook_file_validate.

0

You can use hook_file_validate like this.

function mymodule_file_validate($file) {  
  if (form_get_errors()) {

    // Save errors
    $form_errors = form_get_errors();
    $drupal_errors = drupal_get_messages('error');
    // Clear form errors
    form_clear_error();

    foreach($drupal_errors['error'] as $key => $error) {
      if (in_array($error, $form_errors)) {
        // Unset form errors
        unset($drupal_errors['error'][$key]);
      }
    }

    // Rebuild drupal errors
    foreach($form_errors as $key => $message) {
      if(strpos($message, 'old message') !== false) {
        $message = str_replace('old message', 'new message', $message);
        $_SESSION['messages']['error'][$key] = $message;
        form_set_error($key, $message);
      } else {
        form_set_error($key, $message);
      }
    }
  }
}

I think it helps you.

0

Another way to do this would be to use a hook_form_user_register_alter to add your own submit handler, and within it be sure to call drupal_get_messages() with the clear_queue variable set to true. This will also clear out messages from the queue. Hope this helps!

0

alter the form your submitting

add another function in the $form[#submit] like so

$form['#submit'][] = 'yourFunction';

then and your function

function yourFunction(){
    drupal_get_messages();
    //you can also set your messages here.
}

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.