If a custom form element adds a managed_file
form element during a #process
block the file_ajax_upload()
function issues a notice in file.module
on line 256. In file_ajax_upload()
the logic is trying to get to the form element by traversing the form before the #process callback has been executed.
For instance:
function example_element_info() {
return array(
'example_file' => array(
'#process' => array('example_process'),
),
);
}
function media_file_process($element) {
$element['#tree'] = TRUE;
$element['upload_file'] = array(
'#type' => 'managed_file',
'#title' => t('Upload file'),
);
}
Then when the Upload
button is pressed a notice is shown:
Notice: Undefined index: upload_file in file_ajax_upload() (line 256 of /home/prarie/Documents/Workspace/Drupal/modules/file/file.module).
This looks like it will only mess up the display when a class will never get added at line 270 (and the PHP notice message) and not actual file handling.
It appears to be as simple as adding a call to form_builder
before the traversing the form to find the managed_file element. Will roll a patch once I get my local environment ready to do so.
Comment | File | Size | Author |
---|---|---|---|
#27 | D7_managed_file_1067470-27.patch | 622 bytes | joseph.olstad |
Comments
Comment #1
Prarie CreditAttribution: Prarie commentedPatch that adds the form_builder call before the element traversal.
Comment #2
Prarie CreditAttribution: Prarie commentedComment #3
Prarie CreditAttribution: Prarie commentedChanging version and adding Quick fix tag.
Comment #4
Prarie CreditAttribution: Prarie commented#1: managed_file.patch queued for re-testing.
Comment #5
bfroehle CreditAttribution: bfroehle commentedThis seems like the wrong fix given that form_builder() isn't called anywhere outside of includes/form.inc.
Would it work to just move the file count to below the drupal_process_form() call?
Comment #6
Prarie CreditAttribution: Prarie commentedYou are probably right that calling form_builder is not the right solution. But, moving the count after the the form is processed would mean the delta will always equal and the class wouldn't be assigned to highlight the new files. I'm not sure it would be different with form_builder called earlier either.
Instead, if it's not set then it's not relevant and this patch handles it in a better way, I think.
Comment #7
jasondecamp CreditAttribution: jasondecamp commentedThis patch works for me. I'm surprised this hasn't been committed already.
Comment #8
BassPlaya CreditAttribution: BassPlaya commentedThis patch worked for me as well. Cheers!
Comment #9
gagarine CreditAttribution: gagarine commented#6 Works fine thanks
Comment #10
xjmThanks for the patch and testing. One thing to note is that bugs are fixed in D8 first and then backported to prevent regressions. (Usually the fixes are committed to both branches within a couple weeks of each other.) Reference: http://drupal.org/node/767608
Also, we should add an automated test that reproduces the bug. The test should fail without the patch above, and pass with it. Thanks!
Comment #11
andypostIt's hard to write a test for this case because it require to implement custom element with filefield inside
So let's re-roll this and make inline comment about iteration logic
Comment #12
Prarie CreditAttribution: Prarie commentedWhen I initially opened this issue Drupal 8 hadn't started development (I think). Anyhow, this is rerolled for Drupal 8. Also, added a comment as to why the check is happening.
I remember seeing some instructions for naming the patch so a separate one gets applied to D7 (I would re-roll that one as well to include the comment), but I couldn't find how to do that.
Comment #14
ivanhi CreditAttribution: ivanhi commentedI have written the text below, but I have just realized that It doesn't have to do with the patch because before the patch I wasn't able to see the error of "Referencing to the file used in the "Video" field is not allowed".
I know that it's not the place but I have read a lot of documentation about the problem but not with Drupal 7 and Video module. The problem is only with the thumbnail of the Video Module Update because I upload images in articles and there aren't any problem.
Thank you
-----------
Hi,
First of all thanks for the patch managed_file_1067470.patch. But now I have another problem.
When I edit a node I get the next error: Referencing to the file used in the "Video" field is not allowed.
May be has something to do with the comment "Make sure the path is set: custom form elements might not have added it yet."
But I have created a new form and there is still the error.
Thank you very much.
Comment #15
xjm@ivanhi, you should file an issue in that module's queue. This issue is only about the bug that is being patched in #12. Thanks.
Comment #16
ivanhi CreditAttribution: ivanhi commentedI have found a solution in the next link about the problem or "Referencing to the file used in the "Video" field is not allowed." with the module video and the thumbnails.
http://drupal.org/node/1441626#comment-5660568
Comment #17
andypostThere's is a duplicate issue with different approach #1404480: Notice: Undefined index: in file_ajax_upload() (line 258 of modules/file/file.module).
Still no test on quick fix issue
Comment #18
klonos...coming from #1404480: Notice: Undefined index: in file_ajax_upload() (line 258 of modules/file/file.module).
Comment #19
offroad CreditAttribution: offroad commented#12: managed_file_1067470.patch queued for re-testing.
Comment #21
Prarie CreditAttribution: Prarie commentedIt appears to me that this issue is not relevant to 8.x-dev -- the function
file_ajax_upload()
doesn't exist anymore -- changing the version to reflect. I haven't been that close to version 8 and obviously don't care about this change very much. Removing the assignment to me and will leave this to someone to pick up if anyone cares enough to get the change in version 7.Comment #22
Prarie CreditAttribution: Prarie commented12: managed_file_1067470.patch queued for re-testing.
Comment #24
David_Rothstein CreditAttribution: David_Rothstein commentedThe code has moved to \Drupal\file\FileWidgetAjaxController in Drupal 8, but I'm not sure if the bug exists there or not anymore (the code looks quite a bit different).
Comment #25
joseph.olstadThis issue was created in 2011.
However, back in 2012 someone created a duplicate issue of this one.
Here is the dupe:
#1404480: Notice: Undefined index: in file_ajax_upload() (line 258 of modules/file/file.module).
Comment #26
joseph.olstad8.x branch:
- patch #12 no longer applies
7.x branch:
- patch #6 appears to be still valid, however would be helpful to trigger recent simpletest
Comment #27
joseph.olstadreroll and test
Comment #29
joseph.olstadphp 7 pass, php 5.3 looks like just a testbot issue, requeued.
Comment #30
joseph.olstadok it passed second time around
Comment #31
joseph.olstadComment #32
parasolx CreditAttribution: parasolx commentedI confirmed at the patch #27 still given the error notice after implement.
Comment #33
sjerdoSeems like the reroll in #27 is incorrect.
This line should be removed.