Problem/Motivation

When a poll is configured to allow to view the results before voting, on the poll form a button "View results" disappear.

When going to the poll results as anonymous user (when the poll accepts anonymous votes), a button called "View poll" appears.
But when going to the poll as authenticated user, there is no "View poll" button.

I found out that this bug was introduced in #2944773: View poll button.

Additionally, there is a PHP notice when an authenticated user goes to the poll results before voting, but that's a different bug. And that one only occurs on later PHP versions, so it seems. I shall create a separate issue for this.

I noticed this issue while working on #3178162: Serialization error when switching between poll form and poll results as an anonymous user on PHP 7.4 and there it causes the tests to be less consistent.

Steps to reproduce

  1. Create a poll that allows to view the results before voting.
  2. As an authenticated user, go to the poll. The poll form gets displayed.
  3. Click the "View results" button. The poll vote results get displayed.

There is no "View poll" button, while there is one when accessing the poll as anonymous user.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

A patch with tests will follow. The posted test is similar to the one posted in #3178162: Serialization error when switching between poll form and poll results as an anonymous user on PHP 7.4.

Issue fork poll-3178172

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MegaChriz created an issue. See original summary.

MegaChriz’s picture

This is the tests only patch, I also plan to work on a fix, though that one will be borrowing code from #2909811: Anonymous users - Multiple voting from one IP.

MegaChriz’s picture

Status: Needs work » Needs review
FileSize
3.55 KB

I think that this patch will fix the issue.

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Form/PollViewForm.php
@@ -147,16 +147,8 @@ class PollViewForm extends FormBase implements BaseFormIdInterface {
+      // Voting is no longer allowed.

this is/was a really weird switch statement anyway and you just removed most cases. The $account variable is also unused now. Lets simplify to just a single return show results || isVotingAllowed?

Needs a reroll now anyway because the test conflicts.

MegaChriz’s picture

Here is a reroll + the following changes:

  • The implementation of PollViewForm::showResults() is simplified, following the suggestion from #4.
  • Added function docblock to PollViewForm::showResults().
  • Fixed a single deprecation issue in PollVoteTest::testViewPollAndPollResultsAsAuthenticatedUser(). See https://www.drupal.org/node/3168858.
MegaChriz’s picture

FileSize
2.43 KB

Also adding an interdiff.

Berdir’s picture

the changes to test seem incomplete aka are only the interdiff in all versions of the patch.

MegaChriz’s picture

Not sure why the patches didn't apply. I try with issue branches instead now...

MegaChriz’s picture

askibinski’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.43 KB

MR works as expected, button now appears on results page and works with ajax.
Created a patch based on the latest MR for those that prefer such.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 3178172-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

MegaChriz’s picture

Better hide the patch as it can confuse the testbot. I also triggered a retest for the MR to check if test failures are also in there.

mpaulo’s picture

Is this still reproducible?

seanB made their first commit to this issue’s fork.

ivnish’s picture

BramDriesen’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Assigned: Unassigned » BramDriesen
Category: Bug report » Task
Related issues: +#3426799: Back to poll button only appears when allow anonymous vote is enabled

Partially yes. This seems to simplify some other things as well. Will backport those relevant changes to 2.0.x

  • BramDriesen committed 95e02d9f on 2.0.x
    Issue #3178172 by MegaChriz, seanB, askibinski, Berdir, ivnish: Button "...
BramDriesen’s picture

Status: Needs work » Fixed
Issue tags: +MountainCamp2024

Committed the relevant changes to 2.0.x. Thanks all! The test coverage was increased for this in #3426799: Back to poll button only appears when allow anonymous vote is enabled

BramDriesen’s picture

Assigned: BramDriesen » Unassigned

Status: Fixed » Closed (fixed)

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