Problem/Motivation

There is no way to know what option picked the visitor when displaying thumbs up/down

Proposed resolution

Load the visitors vote and add the bundle in the "has_voted" instead of TRUE so we can set it active in the template preprocess.

Comments

Maune created an issue. See original summary.

maune’s picture

Here is a patch to solve this issue.

maune’s picture

Here is a patch to solve this issue.

maune’s picture

Status: Needs work » Needs review
maune’s picture

StatusFileSize
new1.87 KB

Status: Needs review » Needs work
jhuhta’s picture

Status: Needs work » Needs review
StatusFileSize
new3.61 KB

If I got it right, the patch #3 was supposed to add an 'active' class to the selected option (up or down). However, it didn't quite do it: it was comparing a local $vote_type ('up' or 'down') to a bundle name ('updown'), which was never true.

I rerolled the patch against current dev, enhanced it a bit to cover also yes/no vote and fixed the problem I mentioned. Now it works for me at least.

So now it saves to $has_voted the value of a vote (1/-1), not its bundle.

krzysztof domański’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
krzysztof domański’s picture

Assigned: maune » Unassigned
rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.61 KB
krzysztof domański’s picture

StatusFileSize
new6.41 KB
new6.8 KB

1. Let's leave the property 'has_voted' unchanged. Let's add a new one 'user_voted'.

-        $vote = Vote::load($vote_id);
-        if ($vote) {
-          $has_voted = $vote->getValue();
+        if ($vote = Vote::load($vote_id)) {
+          $user_voted = $vote->getValue();
         }
       }
       $user_can_vote = $this->accountProxy->hasPermission('cast rate vote on ' . $entity_type_id . ' of ' . $bundle);
 
       // Set the theme variables.
       $output['rate_vote_widget'] = [
@@ -113,6 +115,7 @@ class RateEntityVoteWidget {
         '#use_ajax' => $use_ajax,
         '#can_vote' => $user_can_vote,
         '#has_voted' => $has_voted,
+        '#user_voted' => $user_voted,

2. I changed the name of the 'active' class to 'rate-voted'.

3. I changed the css for the 'Thumbs Up / Down' widget.

krzysztof domański’s picture

jhuhta’s picture

StatusFileSize
new2.27 KB

#11 works and looks good and I could've RTBC'd it, but instead added the missing comment lines to the twig templates.

jhuhta’s picture

StatusFileSize
new9.59 KB

Sorry, the #13 patch file was left out.

krzysztof domański’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

krzysztof domański’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.