Dislike button not working

Created on 24 July 2024, 4 months ago
Updated 20 August 2024, 3 months ago

Problem/Motivation

The dislike button is not working correctly; if you press it, it toggles to the like button instead.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇳India Dineshmulluguru Hyderabad

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

Comments & Activities

  • Issue created by @Dineshmulluguru
  • Assigned to sourav_paul
  • 🇮🇳India sourav_paul Kolkata

    Working one it...

  • Issue was unassigned.
  • 🇮🇳India sourav_paul Kolkata

    I've tried to replicate the issue in D10.3 But the like & dislike buttons is not showing on the content page, I've configured it for article content.

    on viewing the content page, its showing this error at the bottom of the page & db log.

    Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 142 of /app/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php)
    #0 /app/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(81): Drupal\Core\Entity\Query\Sql\Query->prepare()
    #1 /app/web/modules/contrib/votingapi/src/VoteResultStorage.php(28): Drupal\Core\Entity\Query\Sql\Query->execute()
    #2 /app/web/modules/contrib/like_and_dislike/like_and_dislike.module(65): Drupal\votingapi\VoteResultStorage->getEntityResults('node', '113', 'like', 'vote_sum')
    #3 /app/web/modules/contrib/like_and_dislike/src/LikeDislikeVoteBuilder.php(75): like_and_dislike_get_votes(Object(Drupal\node\Entity\Node))
    #4 [internal function]: Drupal\like_and_dislike\LikeDislikeVoteBuilder->build('node', '113')
    #5 /app/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(113): call_user_func_array(Array, Array)
    #6 /app/web/core/lib/Drupal/Core/Render/Renderer.php(870): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #lazy_bu...', 'exception', 'Drupal\\Core\\Ren...')
    #7 /app/web/core/lib/Drupal/Core/Render/Renderer.php(411): Drupal\Core\Render\Renderer->doCallback('#lazy_builder', 'like_and_dislik...', Array)
    #8 /app/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, true)
    #9 /app/web/core/lib/Drupal/Core/Render/Renderer.php(165): Drupal\Core\Render\Renderer->render(Array, true)
    #10 /app/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
    #11 /app/web/core/lib/Drupal/Core/Render/Renderer.php(164): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #12 /app/web/core/lib/Drupal/Core/Render/Renderer.php(191): Drupal\Core\Render\Renderer->renderInIsolation(Array)
    #13 /app/web/core/lib/Drupal/Core/Render/Renderer.php(228): Drupal\Core\Render\Renderer->doRenderPlaceholder(Array)
    #14 /app/web/core/modules/big_pipe/src/Render/BigPipe.php(697): Drupal\Core\Render\Renderer->renderPlaceholder('callback=like_a...', Array)
    #15 /app/web/core/modules/big_pipe/src/Render/BigPipe.php(524): Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=like_a...', Array)
    #16 [internal function]: Drupal\big_pipe\Render\BigPipe->Drupal\big_pipe\Render\{closure}()
    #17 /app/web/core/modules/big_pipe/src/Render/BigPipe.php(531): Fiber->start()
    #18 /app/web/core/modules/big_pipe/src/Render/BigPipe.php(283): Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object(Drupal\Core\Asset\AttachedAssets))
    #19 /app/web/core/modules/big_pipe/src/Render/BigPipeResponse.php(113): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse))
    #20 /app/vendor/symfony/http-foundation/Response.php(423): Drupal\big_pipe\Render\BigPipeResponse->sendContent()
    #21 /app/web/index.php(20): Symfony\Component\HttpFoundation\Response->send()
    #22 {main}

    the problem is in .module file

    function like_and_dislike_get_votes(EntityInterface $entity) {
      /** @var \Drupal\votingapi\VoteResultStorageInterface $vote_result_storage */
      $vote_result_storage = \Drupal::entityTypeManager()->getStorage('vote_result');
    
      // Get like votes.
      $like = $vote_result_storage->getEntityResults($entity->getEntityTypeId(), $entity->id(), 'like', 'vote_sum');
      $likes = !empty($like) ? (int) current($like)->getValue() : 0;
    
      // Get dislike votes.
      $dislike = $vote_result_storage->getEntityResults($entity->getEntityTypeId(), $entity->id(), 'dislike', 'vote_sum');
      $dislikes = !empty($dislike) ? (int) current($dislike)->getValue() : 0;

    Even after installing the module the tables 'vote_result', 'vote' was not created in db

  • 🇺🇸United States iamfil

    Please see https://www.drupal.org/project/like_and_dislike/issues/3432104 🐛 Dislike button not working Active . This is a duplicate of that issue.

Production build 0.71.5 2024