Problem/Motivation

It is possible to configure PHP for no upload size limit, in which case the File widget says "Files must be less than 0 bytes", which is useless.

Old code was assumed there is always a limit, while the docs for file_upload_max_size explicity assume this case to be valid.

Attached patch only shows validator hint when a size limit is in effect.

Steps to reproduce

  1. Change the php ini settings as follows:
  2. [PHP]
      upload_max_filesize = 0;
      post_max_size = 0;
      
  3. Add a file field to a content type
  4. Add content of that type and look at the file field

Proposed resolution

Update template_preprocess_file_upload_help() to only display the file size text if the limit value is greater than zero.

Remaining tasks

Address feedback in #7
Write test
review
commit

User interface changes

Before

After

API changes

Data model changes

Release notes snippet

Issue fork drupal-2557319

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mschuster91 created an issue. See original summary.

cilefen’s picture

Version: 7.39 » 7.x-dev
Status: Active » Needs review
cilefen’s picture

+++ b/modules/file/file.field.inc
@@ -555,8 +555,8 @@ function file_field_widget_upload_validators($field, $instance) {
+  if($max_filesize > 0)
+    $validators['file_validate_size'] = array($max_filesize);

The Drupal coding standard doesn't allow inline "if"s, so please convert to curly braces syntax.

cilefen’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs review » Active
Issue tags: +Needs backport to D7

It looks to me as if Drupal 8 has this bug. If I am correct, this must be fixed in 8.0.x first then backported to Drupal 7.

See \Drupal\file\Plugin\Field\FieldType\FileItem (and maybe others).

andyf’s picture

Status: Active » Needs review
StatusFileSize
new821 bytes

I've re-rolled the patch, thanks.

andyf’s picture

StatusFileSize
new1.54 KB

I noticed the same problem at admin/config/regional/translate/import and have added a check to template_preprocess_file_upload_help() to only display the text if the limit's positive.

swentel’s picture

+++ b/core/modules/file/file.field.inc
@@ -157,7 +157,7 @@ function template_preprocess_file_upload_help(&$variables) {
-  if (isset($upload_validators['file_validate_size'])) {
+  if (isset($upload_validators['file_validate_size']) && $upload_validators['file_validate_size'][0] > 0) {
     $descriptions[] = t('@size limit.', array('@size' => format_size($upload_validators['file_validate_size'][0])));
   }

If we do a positive check here, we can remove the check in FileItem I guess ..

andyf’s picture

Thanks, I did think about that but just thought it seemed a bit weird to knowingly return a no-op validator from ::getUploadValidator(). I'm happy to reroll tho (:

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Title: File: Don't display size limit in form when there is no limit configured » Don't display size limit when there is no limit configured for file upload
Version: 8.9.x-dev » 9.3.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative, +Needs tests
StatusFileSize
new7.07 KB
new6.09 KB
new1.65 KB

Problem exists in 9.3.x.

I updated the patch, which works, added screenshots.

Todo:
Address feedback in #7
Add a test.

apaderno made their first commit to this issue’s fork.

avpaderno’s picture

Status: Needs review » Needs work
+  if (isset($upload_validators['file_validate_size']) && $upload_validators['file_validate_size'][0] > 0) {
+      $descriptions[] = t('@size limit.', ['@size' => format_size($upload_validators['file_validate_size'][0])]);

The indentation is wrong by two characters.

+    if ($max_filesize > 0) {
+      $validators['file_validate_size'] = array($max_filesize);
+    }

The short array syntax should be used.

avpaderno’s picture

I am not changing the current status, as the patch is still missing tests.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam changed the visibility of the branch 2557319-dont-display-size to hidden.

dcam changed the visibility of the branch 11.x to hidden.

dcam’s picture

This test is bad as written because upload_max_filesize and post_max_size can't be set with ini_set().

dcam’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Big thanks to @acbramley for the test guidance.

smustgrave’s picture

Status: Needs review » Needs work

is there an existing test we could extend or even turn into a non functional test? Since this test isn't doing a submission it's just showing help text seems overkill to do a full bootstrap for it.

Also proposed solution appears to be empty.

dcam’s picture

Issue summary: View changes
Status: Needs work » Needs review

I converted the Functional test to a Kernel test and updated the proposed resolution.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

dcam’s picture

Status: Needs work » Needs review

Rebased following the move of File module template preprocess functions to a Hook class.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs backport to D7 +Needs Review Queue Initiative
StatusFileSize
new66.23 KB

This seems more like a feature request vs an actual bug.

Removing the D7 backport since D7 is EOL.

Ran the test-only

1) Drupal\Tests\file\Kernel\UploadHelpTest::testUnlimitedFileSize
TypeError: Drupal\Core\StringTranslation\ByteSizeMarkup::create(): Argument #1 ($size) must be of type int|float, string given, called in /builds/issue/drupal-2557319/core/modules/file/src/Hook/FileThemeHooks.php on line 157
/builds/issue/drupal-2557319/core/lib/Drupal/Core/StringTranslation/ByteSizeMarkup.php:28
/builds/issue/drupal-2557319/core/modules/file/src/Hook/FileThemeHooks.php:157
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Theme/ThemeManager.php:293
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:499
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:252
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:142
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:633
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:647
/builds/issue/drupal-2557319/core/lib/Drupal/Core/Render/Renderer.php:141
/builds/issue/drupal-2557319/core/modules/file/tests/src/Kernel/UploadHelpTest.php:33
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Exiting with EXIT_CODE=2

As always thanks @dcam for keeping this as a kernel test!

Manually tested following the IS on a ddev environment.

test

Can see it's doing as advertised.

  • catch committed 5701d455 on 11.x
    Issue #2557319 by mschuster91, cilefen, andyf, swentel, quietone,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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