No summary for comment

Created on 15 September 2024, 7 months ago

Problem/Motivation

Widget for comments always shows "No votes have been submitted yet."

Steps to reproduce

  1. Add widget for comments (I use "number up down")
  2. Enable summary for widget
  3. Vote for comment
  4. Summary shows "No votes have been submitted yet."

Proposed resolution

Needs investigate and fix

🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

ivnish Kazakhstan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ivnish
  • ivnish Kazakhstan

    This is workaround without module patch

    /**
     * Implements hook_preprocess_HOOK().
     */
    function MYMODULE_preprocess_rate_widgets_summary(&$variables) {
      if (isset($variables['vote'])) {
        /** @var \Drupal\votingapi\Entity\Vote $vote */
        $vote = $variables['vote'];
    
        if ($vote->getVotedEntityType() === 'comment') {
          $voting_service = \Drupal::service('plugin.manager.votingapi.resultfunction');
          if ($voting_service) {
            $results = $voting_service->getResults('comment', $vote->getVotedEntityId());
            if ($results) {
              $variables['rate_count'] = $results['updown']['vote_count'];
              $variables['rate_sum'] = $results['updown']['vote_sum'];
            }
          }
        }
      }
    }

    And then use new variables in your summary template

Production build 0.71.5 2024