Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For the managed_file example code, I think a call to file_usage_add should be added right after the file_save line. I think it is important to point this out because if that does not occur, when you go back to your form and try to save it (based on the example code given) you will get an error from file_managed_file_validate saying that the file used may not be referenced.
Comments
Comment #1
jhodgdonSounds like a reasonable suggestion. Thanks.
Comment #2
jhodgdonComment #3
cesarpo CreditAttribution: cesarpo commentedThis hasn't been added to the FAPI documentation, and made me spend the last hour :)
Updated priority so it gets noticed and we save someone from having the same error.
Comment #4
jhodgdonThere are a lot of problems with that page, because it's a beast and very difficult to edit. We're trying to resolve that problem, but it hasn't been done yet.
This particular issue may have caused you some pain (and I'm sorry it did), but it is not any more major than any of the other documentation issues.
Comment #5
jhodgdonFAPI reference file is in the Documentation project now.
Comment #6
jn2 CreditAttribution: jn2 commentedHere's what's in the managed_file example right now:
Here's how I propose to change it, adding the call to file_usage_add:
(Without the call to file_usage_add, file_managed_file_validate produces an error upon saving the form, saying that the uploaded file may not be referenced.)
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commented+
Comment #8
sven.lauer CreditAttribution: sven.lauer commentedLooks good to me, except for the missing space in
I suppose we need a patch? Or do you want to commit this directly once the change is RTBCed?
Comment #9
sven.lauer CreditAttribution: sven.lauer commentedAs I just learned in #8 of #800162: Documentation problem with forms_api_reference.html: give function params for all callbacks, forms_api_reference.html is not patched currently. So RTBCing this.
Comment #10
jn2 CreditAttribution: jn2 commented@sven.lauer
Thanks for the review!
Fixed in both D7 and D8.
Comment #11
sajjo CreditAttribution: sajjo commentedbut now when i press remove button file is not physically removed from directory and from DB as well. yes field is empty but why not from other sources.
Comment #12
jn2 CreditAttribution: jn2 commented@sani723
This issue is just about documentation. If you are having problems with the functionality, you need to find an issue that deals with that or open another issue.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commented@sani723 "it's not a bug it's a feature" :)
If it worked like you want then if I'll have some gallery node and I've removed all images attach to it(imagefield) and I didn't hit the submit button I would lost all images instantly. So it's good that it works like it does because you have to confirm(submit) the form so actions(delete) take place. If you want instant remove you can do it in many ways(add #process function for example). But how it works now is better then the other way.
Comment #15
MohammadMoussa-Lebanon CreditAttribution: MohammadMoussa-Lebanon commentedPlease could you tell me where i have to place your addition , in which file pleas e, this problem is going to make me crazy!!!
Comment #16
jhodgdonIn the Documentation git repository, the file is under developer/topics.
Comment #17
jhodgdonOh sorry. I thought you were talking about resolving this issue, and I didn't realize you were looking for programming help. This isn't a good place to ask for programming help...
There are several support options listed if you click on "Support" at the top of Drupal.org, which will take you to:
http://drupal.org/support
There you can find out about the Drupal IRC channels, and the Forums, which are our two main support mechanisms in the Drupal community.
Good luck with your issue!
Comment #18
MohammadMoussa-Lebanon CreditAttribution: MohammadMoussa-Lebanon commentedthanks dear , you teached me :)