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.
The example implementation of hook_file_copy is empty in the docs.
http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...
Comment | File | Size | Author |
---|---|---|---|
#20 | 1173322-20-file-api-documentation.patch | 1.81 KB | dcam |
#16 | 1173322-16-file-api-documentation.patch | 2.67 KB | dcam |
#13 | file-api_documentation-1173322-13.patch | 1.98 KB | javi-er |
#10 | file-api_documentation-1173322-10.patch | 2.43 KB | javi-er |
#6 | file-api_documentation-1173322-6.patch | 2.42 KB | javi-er |
Comments
Comment #1
arianek CreditAttribution: arianek commentedmoving to the core docs queue
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedWhoops, sorry, thanks!
Comment #3
jhodgdonGood catch, and thanks for reporting! Needs to be fixed in d8, then backported to d7.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedIt turns out that update and move are also not documented.
Comment #5
jhodgdonProbably a good Novice project (hopefully)...
Comment #6
javi-er CreditAttribution: javi-er commentedI guess I qualify as a novice contributor :-)
I looked around for an implementation of these hooks and couldn't find anything, so I did an example where the user name is added at the beginning of the file name on these file operations. Plus a log is saved in the database.
Maybe I was a little enthusiastic on the example and it's a bit too long, let me know what do you think. An alternative it's just adding a log on the database of the current operation.
By the way, this is a working example, I tested it locally.
Comment #8
javi-er CreditAttribution: javi-er commented#6: file-api_documentation-1173322-6.patch queued for re-testing.
Comment #9
jhodgdonThanks! There are a few creative misspellings of the word "beginning" in the code comments, and, the code doesn't quite conform to our coding standards:
should be
there need to be spaces added after if and before {
But... I am not sure these examples will work anyway. It looks like probably these hooks get invoked after the file has already been moved, copied, etc., and they allow a module that is keeping track of files to respond to this event. I don't think that the name will actually be changed by the actions in these proposed hook bodies? You could go to api.drupal.org, look up the hooks, and click on the "1 invocation of hook_*" links to find out for sure... Also, there are a couple of implementations in test modules, so you could look there to get ideas or copy one of those examples.
Thanks!
Comment #10
javi-er CreditAttribution: javi-er commentedHi! I just made those coding standards modifications, please take a look to the attached patch.
About the example, this is a working example. I create a new module and wrote the code there, once I made sure that it was working bug-free I copied and adapted it to the example documentation.
Maybe the example is a bit complex, I can make it so it just write a line in the Drupal log instead.
Bellow is a description of what the code does:
Comment #11
javi-er CreditAttribution: javi-er commentedComment #12
jhodgdonGreat! I think that the code is clear and these are good examples.
The only thing that I think needs attention is the in-code comments:
- Normally comments in code use verbs like "Load the ..." vs. "Loads the...".
- In the comments that say "...the user name is contained at the beginning of the uploaded file." it should say "file name" at the end.
- Say "Check whether..." instead of "Check if..."
- I don't think that the watchdog() line needs a comment at all (it should be obvious what that line is doing without a comment). Same with the user_load() line. Actually, I think maybe just one comment at the beginning saying "Make sure that the file name starts with the owner's user name." would be enough?
Comment #13
javi-er CreditAttribution: javi-er commentedI agree that just a comment should be enough, in general the rule is that any code that's not self-explanatory should be commented and in this case simply stating what the code does should be enough, in the first patch I went with as much comments as possible since some examples I saw before starting seemed to be using as much comments as possible.
Attached is a revised version, let me know what do you think.
Thanks for the grammar corrections, I'm not too good at it since English isn't my primary language :-)
Comment #14
jhodgdonThanks! Looks good, committed to 8.x. The patch doesn't apply to 7.x, so it needs to be ported.
Comment #15
joshf CreditAttribution: joshf commentedComment #16
dcam CreditAttribution: dcam commentedBackported #13 to D7.
Comment #17
dcam CreditAttribution: dcam commentedComment #18
jhodgdonLooks good, thanks!
Comment #19
jhodgdonI cannot get the patch above to apply to d7 currently.
Comment #20
dcam CreditAttribution: dcam commentedRerolled #16.
Comment #21
jhodgdonThanks! I'll get that committed shortly.
Comment #22
jhodgdonThanks again - committed to 7.x.