To be able to update to latest dev of Commerce, I was forced to also update IEF to dev (I was using alpha5 before). With alpha5, I didn't have any problems, when my referenced entities are having image fields.
Now, the image upload doesn't work at all anymore. After selecting an image from disk, the upload request is sent normally, as you can see the Ajax loading spinner. But after finishing the request, there's still "no file selected".
In the watchdog logs, I could find two PHP warning per upload trial:
Warning: Invalid argument supplied for foreach() in Drupal\file\Plugin\Field\FieldWidget\FileWidget::submit() (Zeile 548 in /var/www/drupalvm/drupal/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php).
And before same warning in line 539.
I did a short debugging and found out, that the value of $submitted_values is NULL.
$submitted_values = NestedArray::getValue($form_state->getValues(), array_slice($button['#parents'], 0, -2));
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 2691727-fix-image-upload.patch | 5.46 KB | bojanz |
| #22 | 2691727-fix-image-upload.patch | 4.83 KB | bojanz |
| #17 | inline_entity_form-ajax-fileupload-fix-2691727-17.patch | 1.99 KB | yce |
| #16 | inline_entity_form-ajax-fileupload-fix-2691727-16.patch | 1.96 KB | yce |
| #14 | 2691727-14.patch | 10.21 KB | dawehner |
Comments
Comment #2
agoradesign commentedComment #3
agoradesign commentedComment #4
Maikel commentedI am looking at the same issue, i also found this one that seems closely related. https://www.drupal.org/node/1329856.
I am not able to pinpoint the source of the problem yet, but it seems that the field collection issue implies to have fixed the problem / found a fix.
At the moment i am testing the same setup with field collection 8.x-1.x-dev (8.x-2.x-dev does not really do anything as it seems) and inline entity form 8.x-1.0-alpha5 (gonna try dev now) to see if it persists.
Maybe this helps, i will at least report my findings.
Comment #5
agoradesign commentedThanks for the information. I've scanned the FC issue - there's comment mentioning this issue #1545584: Problem when using Image field with field collection, which really looks closely related.
However, I've also looked at the commits after alpha5, trying to find the one that caused the regression. At first sight, nothing seems suspicious. most likely this one: http://cgit.drupalcode.org/inline_entity_form/commit/?h=8.x-1.x&id=30589...
Maybe you can find the time to test the dev version, but with the mentioned commit reverted?
Comment #6
Maikel commentedChecked out the dev version of Inline Entity Form and reverted this commit http://cgit.drupalcode.org/inline_entity_form/commit/?h=8.x-1.x&id=30589... but no cigar.
Also tried uninstalling field_collection all together, but still nothing.
Comment #7
Maikel commentedJust to be sure field_collection does not break anything in this particular case. I reinstalled alpha-5 and re-enabled field_collection and everything started working again.
Comment #8
agoradesign commentedI'm not using field_collection at all, so this can't be the cause. In my current project, I have reinstalled the whole site several times during development, without this problem. But yesterday I switched from alpha5 to dev - now I have the problem
Comment #9
bojanz commentedSounds like the same problem from #2690093: The simple widget can't be embedded inside a complex one. We're making progress on test coverage and a fix there.
Comment #10
agoradesign commentedYou're right, sounds very similar. I'll add the other as related issue, but don't close this as dupe, as long we're not 100% sure
Comment #11
bojanz commentedI won't. We'll want to add test coverage here at least (our tests should have an image field, to prevent future regressions)
Comment #12
bojanz commentedWe need a test here before we can proceed. Unfortunately, I won't have IEF time this week.
Comment #13
dawehnerI'm looking into it.
Comment #14
dawehnerUploading the breaking test for now.
Comment #15
bojanz commentedAfter a lot of debugging we realized that the last line can't work. We need to remove it, then change extractFormValues() to use the $element['#entity'] property instead of the submitted values acquired via $form_state->getValue().
Comment #16
yce commentedThe setValueForElement() method doesn't need to be removed completely as bojanz mentioned (btw, thanks for pointing me to the right direction :) ), it just needs a condition, to check whether if it was a file upload or not, and set the values for the element only if it wasn't a file upload.
I've tested it with nodes, and with a custom bundle-less entity (applied the patch from https://www.drupal.org/node/2569193 for it) and it worked for both files and images.
I've attached a patch for it.
Comment #17
yce commentedWhops, the condition was not quite right, fixed it.
Comment #18
bojanz commentedI fixed a notice introduced in #17, but tests still fail with the patch from #17: https://travis-ci.org/bojanz/inline_entity_form/jobs/120569592
Problem is that even if we skip that line on file upload, the widget extractFormValues() methods run. And I don't think we can skip them completely.
So the best option is to keep exploring #15.
Comment #22
bojanz commenteddawehner's test patch breaks the build completely even with the fix.
For some reason, testEntityCreation() starts failing as soon as the inline form has an image field.
The Some reference/John/Doe form doesn't get saved, we instead get an empty form back, but that form belongs to the all_bundles IEF element, not the multi IEF element (they look the same but have different form names).
Meanwhile, enabling the test module and using the browser works fine.
I think this is unrelated to the current regression, but it certainly confuses things.
Attaching the current fix. It fails the existing nested tests.
I'm going to try cleaning up our nested hacks in another issue, with hope that it will help here. triggeredByCurrent() and the "if ($values['form'] == 'add') {" part of extractFormValues() should not need to exist.
Comment #23
bojanz commentedComment #25
bojanz commentedUpdated patch, skipped a commit.
Comment #26
agoradesign commentedLet's change this to Needs review to see, if the green lights now go on...
Comment #29
bojanz commentedCommitted the fix that passed tests.
Opened a followup for tests #2701397: Add tests for image fields, since I couldn't get dawehner's to pass (even though manual testing works).
Also cleaned up the mentioned triggeredByCurrent: #2700571: Remove EntityInlineForm::triggeredByCurrent.
EDIT: Manual testing show sthat an image field inside an IEF form element (not a widget) still fails, so it's possible we have additional bugs here.
Comment #31
heddnClosed #2719035: Image upload on core 8.1 and entity_browser-dev fails as duplicate.