My website has content type "album" which has field "field_photo". The field is multivalue i.e. the album consists of multiple photos.
I also have content type "Player" for individual players.
I'm writing an "imagefield_reference" module which allows me to "tag" players to photos.
The "tags" are autocomplete textfields where I can add a reference to a "player" node from an individual photo. There can be multiple players in one photo as shown in the example screenshot above.
What I want to ultimately do is that I want to show the photos of the player on that specific player's page.
Here comes the question (Drupal 7)
This is what I'm doing on a player node
- On a player node, I know the NID of the player
- I then load from my imagefield_reference module's DB table the file ids (FID) where the player has been tagged. (I also know the album's NID)
- I now have the file ids in $fids array.
- I load all the relevant image files (and only them) using file_load_multiple($fids)
- This returns me an array of files
- I can easily then show a thumbnail of the file and link to a bigger image using Colorbox module
Here's where I'm stuck:
- file_load_multiple($fids) does NOT return the "title" (or "alt") field of the photo.
- I want to load the title of the photo so that I can pass that to Colorbox so that Colorbox can show the photo title as a caption.
- How to load the title (or alt) of the image in the most elegant way?
- I definitely don't want to load the full "album" nodes when I'm viewing the player node.
- One player can be tagged in N albums but it might be that in some album she is only appearing in one single photo. Loading full N album nodes would be a total performance nightmare.
- Of course I could go directly to the database and load the photo titles with a direct SQL query but that's not the Drupal way to do it. I'm quite sure there is a more elegant way to do this.
- I've been trying to play with EntityFieldQuery but so far I've not been able to build a query that would do what I'm loooking for...