API page: http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...

Describe the problem you have found:

The sample function body for hook_file_download is totally bogus for D7/8 - it was never updated from the D6 version. Does this hook still exist? If so, the example needs an update to something relevant for D7/8, and if not, it needs to be removed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

It does look like hook_file_download() is still valid -- it's invoked from file_download(), which is at least called once in core.

So we just need a different example, taken from one of the core modules that implements it. And the @see to upload_file_download() should be removed as well.

jhodgdon’s picture

Issue tags: +Novice

Good project for a novice doc contributor...

FreekyMage’s picture

Assigned: Unassigned » FreekyMage

Going to try and solve this to learn how to contribute

FreekyMage’s picture

Status: Active » Needs review
FileSize
1.02 KB

This hook gets used in file_file_download, image_file_download and user_file_download. Because the first 2 are pretty large I used the user one. I don't know if that's the best sollution since it doesn't return -1 when access is denied.

Anyway, hooray for first patch \o/

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7

Hooray indeed! Thanks - looks good, and I think you made the right decision to use a simpler example.

Should go into 7.x/8.x.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Congrats, FreekyMage! :D

While you are simply following our documentation standards by copy/pasting an example out of core, the previous example was a bit more complete, since it also showed an example of denying access to the file. So we actually lose some helpful information with this patch. :(

Can we embellish a bit on what user.module supplies and throw in an access check for, say, "user_access('access user profiles')" and deny access in that case?

Additionally, a line or so of comments within the example code here explaining what is going on would be good. We lost the "// Check if the file is controlled by the current module." context from the old text.

jhodgdon’s picture

Status: Needs work » Needs review

Gracious, really??? Many of the core hook docs don't have examples that cover all the contingencies -- far from it. I think we should just let this go. Can we reconsider?

Also, we need to change the standards for hook docs ASAP, so we don't have to think about going through this ridiculous exercise of trying to find a core example that covers all the contingencies. We need the API module to just list the functions that implement each hook automatically so we don't have to put in a sample function body. Does anyone use them anyway -- wouldn't you just go look at a core example? Sigh. Anyway, discussion for a different issue...

webchick’s picture

Well, yeah, really. Denying download access to files is an important function of this hook. If they can't see how to do it in the hook example, how are they supposed to figure out how to do it? Read http://api.drupal.org/api/drupal/modules--file--file.module/function/fil... ? EEEK. :)

FreekyMage’s picture

Thanks for the input. I also thought the example could be better so I made a new patch.

jhodgdon I'm with you that the api module should list the functions as long as they are viewable on the website here so people can look at it without needing opening an editor and locating it.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks OK to me. 8.x/7.x...

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Nice! Looking much better now.

Does this actually work, though? My sneaking suspicion is that this code as written would deny access to all files, not just the files that that module controls, if the requisite permissions were missing. I'm pretty sure that check needs to go inside the if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) { condition...

Sorry to be a PITA on this, but this is the primary way we have to educate developers on how these hooks work, so it's important the docs be correct. :(

jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: -Novice

Agreed with #11. Sigh. Not so much of a Novice issue any more. :)

FreekyMage’s picture

Status: Needs work » Needs review
FileSize
1.13 KB

You're right, I should have checked the function better. I'm more of a themer normally and so my logical brain shuts down from time to time :)

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

At the risk of webchick once again rejecting the patch, I think it's good (again). :)

8.x/7.x if it's OK...

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Shoot, sorry! This totally fell off my radar.

This looks great! Thanks for all your work on this.

Committed and pushed to 8.x and 7.x.

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