I have a content type called Task, where I add tasks. After task being completed, I would like the node author to rate his satisfaction using Fivestar field.

While viewing the node (not in edit mode), how to enable voting on this satisfaction rating field by node author only on his task but others can't vote, they can see his/her vote.


Here is an alternative answer, specific to the case where the voting happens on the frontend (using the "rated while viewing" widget).

  1. Under "Manage Fields", configure your rating/fivestar field to use the widget "Stars (rated while viewing)". You also must configure the options:

    • Allow users to vote on their own content: This must be on
    • Allow users to cancel their ratings: This is optional
    • Allow users to re-vote on already voted content: This should be off
  2. Under "Manage Display", configure your rating/fivestar field to disallow voting via AJAX:

    • Allow voting on the entity: This must be off, we will modify this dynamically
  3. In a custom module, you should implement the following hook. It will activate the "Allow voting on the entity" only for the author of the node.

     * Implementation of hook_field_display_ENTITY_TYPE_alter().
    function yourmodule_field_display_node_alter(&$info) {
      if($info['type'] == 'fivestar_formatter_default') {
        global $user;
        $node = menu_get_object('node');
        if($node && $user->uid == $node->uid) {
          $info['settings']['expose'] = TRUE;

This configuration+code delivered the result you wanted on my sandbox instance, hope it works for you!

  • I'll try that code. Just as small question, is "Allow users to re-vote on already voted content" will break the solution, I need this option because the content type had 2 fivestars fields so disabling this will only allow user to vote on 1 field but not the 2nd one. – Rami Sedhom Mar 25 '16 at 15:24
  • The "Allow users to revote on already voted content" option is field specific. The code applies to all fivestar fields. It may be possible to filter out the other fivestar fields based on the other data available in the $info array. You should update your question with the new information. – Stefanos Petrakis Mar 25 '16 at 16:34
  • It works fine even with 2 fivestar fields and with the option "Allow users to re-vote on already voted content" enabled. – Rami Sedhom Mar 26 '16 at 3:45
  • Great to hear it worked! – Stefanos Petrakis Mar 26 '16 at 7:10

Here are the steps you need to allow only the node author to rate the node.

  1. For the Task content type, change the role permissions so that only the authenticated users (or whichever role you want to allow to complete and rate Tasks) have the "Edit own content" permission.
  2. Under "Manage Fields" for the Task content-type, configure your rating/fivestar field to use the widget "Stars (rated while editing)". Now, only the node's autor can edit and rate a Task node. The vote will still be visible to other users.

Hope this helps!

  • Thanks @Stefanos for help, but the real issue that I like the node author (Task Owner) to rate while viewing (i.e. I don't want node author to go to node edit to be able to rate). May be I should add that point into the question to make it more clear. – Rami Sedhom Mar 24 '16 at 13:55
  • Hello @Rami, it seems that this is a situation that needs some coding, configuration won't do it. How are your conding skills? – Stefanos Petrakis Mar 24 '16 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.