1

Background

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.

screenshot

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?

Some considerations

  • 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...
2
  • The only API available for that is node_load() (or field_attach_load() more specifically). It can be pretty database heavy, so if that's a concern just go straight into the field tables. Or try the field_attach_load() single field option. An EntityFieldQuery will just get you some entity IDs, you'd still need to load up the entities to get at the field data
    – Clive
    Feb 1, 2014 at 12:06
  • @Clive, thanks for a quick reply. I think I will go read the photo titles directly from the field tables as you suggested. Feb 1, 2014 at 13:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.