This is a take off on field_file_references().
My use case: I hook into hook_file_insert() and need to act on the file only if it belongs to a certain node.


Title:Get nodes referencing a fileGet node referencing a file
new830 bytes

Actually, I think there can be only a single node referencing the file.

new879 bytes

hmm, but there might be several revision. sorry, Patch is the same as the original.

new1.03 KB

Thanks Amitaibu. I've been considering the improvement of FileField APIs and I think this would be a great thing to include. However I'd like clean it up a little bit and clarify its usage.

I rerolled this patch with the following changes:
- Renamed to filefield_get_file_references() and placed in the new APIs section of FileField (see #417774: Add Public FileField API Functions (Fix field_file_references())).
- Changed the parameters to use a $file object instead of array. I know this is a bit of mess since field_file_load() returns an array, but all our other API functions expect $file objects.
- Removed the quirky "$get_field" parameter. This function should do exactly what its meant for and I could see this being used for all kinds of strange loading.
- Changed the return value to be an array of NIDs, each containing an array of revisions within that node. I think most users will just be interested in the NIDs, so I wanted to make it easy to get to them while still making the VIDs available.

Let me know what you think of this version and if it'd be acceptable for your purposes. Thanks!

Status:Needs review» Reviewed & tested by the community

yeah, works properly, thanks :)

Status:Reviewed & tested by the community» Needs review

Thanks Amitaibu, while working with #369560: Get array of files attached to node I've been thinking that we should probably make the $field parameter optional, so you could get all nodes referencing a file regardless of what field it's in. The #369560 patch also currently uses $field_name instead of $field, which I could see as being quite helpful in a public API when users don't know how to get a field through content_fields().

Status:Needs review» Fixed

See the final patch in that incorporates this API function also. It works the same as the patch in #3 only $field can be a field name string, a field array, or NULL (to get references within all fields).

Status:Fixed» Closed (fixed)

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