Update element description file size limit

Created on 27 February 2023, almost 2 years ago
Updated 24 March 2023, over 1 year ago

Problem/Motivation

When using the Uppy widget the file size limit is set to the the lower of the field file size limit or the PHP max upload limit. Since using Uppy allows you to bypass the PHP Max Upload limit this is pointless.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jrglasgow Idaho

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

Comments & Activities

  • Issue created by @jrglasgow
  • πŸ‡ΊπŸ‡ΈUnited States jrglasgow Idaho

    here is a patch that is working on my local system

  • @jrglasgow opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States jrglasgow Idaho
  • πŸ‡ΊπŸ‡ΈUnited States jwjoshuawalker San Diego

    I'm confused on the wording. It looks like this patch is adding field validation to ensure that it obeys max upload size settings, is that correct?

    While reading, I initially interpreted this as "let's just ignore max upload settings"; and I don't want to take that control away from site administrators.

  • πŸ‡ΊπŸ‡ΈUnited States jrglasgow Idaho

    in FileItem::getUploadValidators()

      // Cap the upload size according to the PHP limit.
      $max_filesize = Bytes::toNumber(Environment::getUploadMaxSize());
      if (!empty($settings['max_filesize'])) {
        $max_filesize = min($max_filesize, Bytes::toNumber($settings['max_filesize']));
      }
    
      // There is always a file size limit due to the PHP server limit.
      $validators['file_validate_size'] = [
        $max_filesize,
      ];
    

    you see that the file_validate_size validator is set to the minimum of the Widget max_filesize and the PHP Max Upload size.

    In the FileWidget::formElement() the description is set using those upload validators.

         $file_upload_help = [
            '#theme' => 'file_upload_help',
            '#description' => $element['#description'],
            '#upload_validators' => $element['#upload_validators'],
            '#cardinality' => $cardinality,
          ];
          $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
    

    The File size listed in this description is pulled out of the validators in template_preprocess_file_upload_help()

      if (isset($upload_validators['file_validate_size'])) {
        $descriptions[] = t('@size limit.', [
          '@size' => format_size($upload_validators['file_validate_size'][0]),
        ]);
      }
    

    The actual validation for the file size using the Widget settings works fine as the comparison doesn't bother to look at the PHP Max Upload setting, as after it is uploaded it is too late to worry about that, but the description is already set.

    This patch updates the validator file_validate_size with the correct size based on the field setting and recreates the description since the PHP Max Upload size limitation doesn't matter when using Uppy to upload files.

  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jwjoshuawalker San Diego

    I understand, thank you for the explanation.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024