Closed (fixed)
Project:
FileField
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
22 Feb 2009 at 16:37 UTC
Updated:
26 Apr 2009 at 20:40 UTC
Jump to comment: Most recent file
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | filefield_get_references.patch | 1.03 KB | quicksketch |
| #2 | file_get_references.patch | 879 bytes | amitaibu |
| #1 | file_get_references_1.patch | 830 bytes | amitaibu |
| file_get_references.patch | 879 bytes | amitaibu |
Comments
Comment #1
amitaibuActually, I think there can be only a single node referencing the file.
Comment #2
amitaibuhmm, but there might be several revision. sorry, Patch is the same as the original.
Comment #3
quicksketchThanks 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!
Comment #4
amitaibuyeah, works properly, thanks :)
Comment #5
quicksketchThanks 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().
Comment #6
quicksketchSee the final patch in http://drupal.org/node/369560#comment-1467494 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).