I'm looking for a way to build a simple gallery node type in Drupal, with vote (with Votingapi and Fivestar)per image enabled. (1 vote per image, per node, per user, and users are able to vote on any image in the node). As simple as it looks, I'm unable to build a simple proof of concept of what I'm trying to achieve.

Here's a mockup of how I see the thing, and here's how I see the thing in Drupal. A content type 'Gallery' these following fields:

  • Title
  • Body
  • Field Collection (multiple):
    • Image (single)
    • Fivestar rating

I succeeded to do it and now, to compute the results, I would like to get the results per node. However, if you look into the votingapi_vote table, the only data for a vote are:

MariaDB [voting]> SELECT * FROM votingapi_vote;
| vote_id | entity_type           | entity_id | value | value_type | tag  | uid | timestamp  | vote_source |
|      10 | field_collection_item |         2 |    80 | percent    | vote |   1 | 1455270089 |   |
|      13 | field_collection_item |         3 |    60 | percent    | vote |   1 | 1455271926 |   |
|      15 | field_collection_item |         1 |    80 | percent    | vote |   1 | 1455272041 |   |

It is impossible to retrieve data from the parent node because it simple doesn't exists in the DB.

It looks like we could change tags dynamically, so I hooked into fivestar to generate dynamic tags, but it gets blocked in _fivestar_cast_vote(), especially in fivestar_validate_target(), and I'm unable to generate tags dynamically.

I also tried to hook into Votingapi using hook_votingapi_preset_votes_alter() but if you're using Fivestar with the AJAX widget, it's impossible to get information on the current node using menu_get_object(). So I'm still stuck.

Now I'm trying to look for another solution, if you have ideas, please let me know.

  • Would it be an option to use rules to apply a vote from the field collection item onto the parent item? Commented Feb 13, 2016 at 11:46
  • That would be way too complicated. We should be able to use the 'tag' field instead. Fivestar doesn't allow to use dynamic tags, so, I don't know what to do yet. I'll see.
    – user334
    Commented Feb 15, 2016 at 8:29
  • Maybe you should have a look at the Answers module for such gallery, whereas you'd replace your field collection with "answer"-nodes, and the question-nodes would be used for the title and body. For more details, have a look at my answer to this question. Commented Jul 15, 2016 at 7:11

1 Answer 1


1 vote per image, per node, per user, and users are able to vote on any image in the node

I don't fully understand the use case here; it might be easier to visualise the scenario with a fuller explanation?

At a guess, the issue might revolve around the use of field collection module here? I'm not a wizard at the internals of that, but personally in this situation I usually manage this with a container/item setup:

  • Gallery (node/entity)
    • Image (node/entity)
    • Image
  • Gallery
    • Image
    • Image

I then relate these either with entity_reference or I guess you could use inline entity form, depends. I don't know if there is anything that precludes you from doing it this way, but I think you're more likely to have better data from votingapi et al like this? Probably using two content types is going to give more joy than entities for that reason.

This is all from a site builder perspective, where using this kind of setup generally means I have to write as near to zero code as possible!

  • Here's a simple mockup of what I'm trying to do. And yes, users are able to vote on any images, once. Then can vote on all the images or only some of them. To compute the values, we must use a bayesian computation.
    – user334
    Commented Feb 12, 2016 at 13:44
  • The thing is that to compute the bayesian computation, you have to use all the values of the vote of the node. This is why we need a tag per vote.
    – user334
    Commented Feb 12, 2016 at 14:03

Your Answer

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