Little correction for process of preparing the description of the file upload field

Created on 16 October 2015, about 9 years ago
Updated 31 January 2023, almost 2 years ago

Hello

I've developed module Forbidden File Format
The logic of this module based on disabling of upload validator 'file_validate_extensions' and adding my own validator.

It's possible if I'll do this:

$item['#upload_validators']['file_validate_extensions'] = array();
then Drupal will allow to upload any types of files.

But I have a problem in function template_preprocess_file_upload_help()
There is this code

 if (isset($upload_validators['file_validate_extensions'])) {
    $descriptions[] = t('Allowed types: @extensions.', array('@extensions' => $upload_validators['file_validate_extensions'][0]));
  }

In my case the $upload_validators['file_validate_extensions'] is empty array and IF returns TRUE, but index 0 in $upload_validators['file_validate_extensions'][0] isn't set and I get notice.

In the multiple mode of field function "template_preprocess_file_upload_help" execute from this code

     $elements['#file_upload_description'] = array(
        '#theme' => 'file_upload_help',
        '#description' => '',
        '#upload_validators' => $elements[0]['#upload_validators'],
        '#cardinality' => $cardinality,
      );

and there is no way to avoid this notice. If I'll unset $upload_validators['file_validate_extensions'] then Drupal will allow default extensions of file. But I should allow all extensions in Drupal and deny some extensions in my module.

I think that more logical is check that index 0 also has been set.

Feature request
Status

Postponed: needs info

Version

9.5

Component
File system 

Last updated about 12 hours ago

Created by

🇷🇺Russia eugene.ilyin

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024