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.

Support from Acquia helps fund testing for Drupal Acquia logo

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

Status: Needs review » Needs work
jhuhta’s picture

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
FileSize
3.61 KB
Krzysztof Domański’s picture

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

FileSize
2.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

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.