Maximum Image Resolution image field setting ignored

Created on 16 October 2023, over 1 year ago

If I add an Image field to a content type and configure it with a maximum image resolution (e.g. 1500 x 1500 pixels) then the default Drupal image widget will resize larger photos to 1500 pixels maximum.

If I change the widget on the Form Display tab so that it uses Plupload Widget instead of the default, then I can upload a much larger file (as long as it is below the PHP upload size limit) and it will no longer be resized - it seems to bypass the Drupal maximum image resolution setting.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom johnvb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @johnvb
  • 🇧🇪Belgium barry75

    I traced the issue to function ImageWidget::process() in the file /modules/contrib/plupload_widget/src/Plugin/Field/FieldWidget/ImageWidget.php :

    // Replace the upload HTML element with PLUPLOAD
        // for a single file.
        $element['upload'] = [
          '#type' => 'plupload',
          '#title' => t('Upload files'),
          // '#description' => t('This multi-upload widget uses Plupload library.'),
          '#autoupload' => TRUE,
          '#autosubmit' => TRUE,
          '#submit_element' => "[name={$element['upload_button']['#name']}]",
          '#upload_validators' => $configuration->validators,
          '#plupload_settings' => [
         ...
    

    This code places NEW $element['upload']['#upload_validators'], that apparently gets priority over the already existing $element['#upload_validators'].

    A quick solution: at the end of the function, add this line:

    	// replace the upload validators with the original upload validators
    	$element['upload']['#upload_validators'] = $element['#upload_validators'];
    
    	return $element;
    

    Please review...
    This could be done more elegant, but I'm not sure about the function of the $configuration->validators variable ?

Production build 0.71.5 2024