Example consequences

The easiest way to see the problem is using Image Field.

  • Create a content type
  • Add image field "Image Single" with 'Allowed number of values' = 1.
  • Add image field "Image Multiple" with 'Allowed number of values' = 'Unlimited'.
  • Create a new node of this type
  • Click browse on "Image Single": browser correctly shows only images
  • BUG: Click browse on "Image Multiple": browser shows all files

Expected behaviour: "Image Multiple": browser shows only images

The reason for the bug is that the 'accept' attribute is missing.

Other consequences

This bug is not necessarily specific to Image, hence I set component = "file system". The 'data-drupal-selector' attribute is missing too - not sure what effect that has.

Code problem

See \Drupal\Core\Render\Element\File::processFile, where existing value of #attributes is overwritten. However there could be valid and important attributes already present.

Proposed solution

Keep existing attributes and in addition set 'multiple'

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AdamPS created an issue. See original summary.

AdamPS’s picture

Status: Needs review » Needs work

The last submitted patch, 2: file-attributes.2916595-2.patch, failed testing. View results

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

phenaproxima’s picture

Issue tags: +Media Initiative, +blocker

This blocks some refactoring work on the Media Library module, so tagging this issue appropriately.

phenaproxima’s picture

Status: Needs work » Needs review
FileSize
1.96 KB
2.56 KB

Here we go. There's no test coverage that exactly hit the problem spot, so I wrote some new stuff for that. If anyone can suggest an existing place that this might fit better, please let me know.

The last submitted patch, 7: 2916595-7-FAIL.patch, failed testing. View results

Wim Leers’s picture

Issue tags: +BarcelonaMediaSprint

Will review.

Wim Leers’s picture

Status: Needs review » Needs work

This looks great, and I'm surprised this was only discovered recently, since it must have been around for a long time!

It does fix the bug, but doesn't explicitly test the original bug report. I don't think it makes sense to have an explicit regression test for such a specific sequence of steps, so I did manual testing to verify it indeed fixes the originally reported problem! ✅

Just two nits:

  1. +++ b/core/modules/system/tests/src/Kernel/Form/FileElementTest.php
    @@ -0,0 +1,26 @@
    +  protected static $modules = ['form_test'];
    

    Nit: needs @inheritdoc

  2. +++ b/core/modules/system/tests/src/Kernel/Form/FileElementTest.php
    @@ -0,0 +1,26 @@
    +  public function testFileElement() {
    

    Nit: needs one-line comment

  3. +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestFileForm.php
    @@ -0,0 +1,42 @@
    +        'class' => ['test'],
    

    Nit: I suggest s/test/cagatio/

phenaproxima’s picture

Status: Needs work » Needs review
FileSize
2.68 KB
1.13 KB

All fixed. Thanks!

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

👍

phenaproxima’s picture

#11 will fail. I should probably run tests locally before I post patches.

The last submitted patch, 11: 2916595-11.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f7f07d81ac to 8.7.x and 5a42530358 to 8.6.x. Thanks!

Backported to 8.6.x since this is a bugfix that has very limited BC impact.

  • alexpott committed f7f07d8 on 8.7.x
    Issue #2916595 by phenaproxima, AdamPS, Wim Leers: File element discards...

  • alexpott committed 5a42530 on 8.6.x
    Issue #2916595 by phenaproxima, AdamPS, Wim Leers: File element discards...

Status: Fixed » Closed (fixed)

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

idebr’s picture

Version: 8.7.x-dev » 8.6.x-dev
Wim Leers’s picture