Allow admins to alter number of votes cast for a poll

Created on 26 February 2019, almost 6 years ago
Updated 5 April 2023, almost 2 years ago

We are migrating a few polls from an old site (D7) to a new one (D8), and we need a way to create a poll on the D8 site and set a certain number of votes for each choice to start off with, so it reflects the data from the D7 site's poll. Currently there is no way to manually choose how many votes each choice currently has.

Feature request
Status

Needs work

Version

1.4

Component

User interface

Created by

🇺🇸United States TerranRich

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    I rewrote a patch from scratch that is using the PollChoice entity as @Berdir indicated.

    https://git.drupalcode.org/project/poll/-/merge_requests/16.patch

    The merge request basically just add a new property "starting_votes" on the PollChoice entity. And then it was just a matter of changing the functions to calculate the totals to use that additional property when needed.
    There is a hook_update to run in order to get that new property installed in case the module was already enabled.

  • Status changed to Needs review almost 2 years ago
  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
  • Status changed to Needs work 10 months ago
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪
  • ivnish Kazakhstan

    @Bram, this is cool and necessary feature. +1 from me

  • Pipeline finished with Success
    4 months ago
    Total: 205s
    #300941
  • ivnish Kazakhstan

    I manually tested - works as expected. Still needs automated tests. I'm working on it

  • 🇬🇧United Kingdom naheemsays

    One issue I have with this patch that can probably be worked around is that its called "starting votes". it can be used for many other things so a more generic term like offset might help.

    (example would be manual votes where some use the form and others or no members tell the admin to add them).

    Not sure if it is also relevant to here, but the current migrations do not migrate these offsets. Does that need to be added?

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    I can understand this from a migration perspective.

    But what would be the practical need for a content editor to be able to set a starting position for a poll? This seems a bit... unfair/wrong? Just imagine doing a poll about elections on a site, and the content editor is able to bias the results for one (or more) options by changing the starting vote.

  • ivnish Kazakhstan

    There are different projects with different cases. I have some private projects which needs this functionality. And not only me, this issue has 10 followers :)

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    The initial request was for migrations, which I totally understand! So I think that's where the majority of followers is coming from.

    The issue title describes "admins", I don't see anything permission related in the code. So I would implement logic to only show this for the administer poll permission. Or provide a new permission for this so it can be granted to specific roles. But I'm highly against this just being added as a default option for all content editors who can create polls.

  • ivnish Kazakhstan

    This functionality disabled by default and needs to enable this in Poll Choices Widget here /admin/config/content/poll/form-display

    Usually content editors don't have permissions to change Field UI settings

    I will develop migrations

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    > Usually content editors don't have permissions to change Field UI settings

    Correct, but if an admin enables the field, it's visible for all content editors? Or am I wrong here :-)

  • ivnish Kazakhstan

    Yes, correct. I will try to improve it :)

  • ivnish Kazakhstan

    @Bram, I need advice on migrations. In Drupal 7, user votes and admin votes are added together. What is the best way to migrate? Subtract user votes from the total number of votes and these will be admin votes for starting_votes new field?

  • 🇬🇧United Kingdom naheemsays

    I would suggest there would need to be a count of all votes (for the option), compare it with the total recorded votes and what remains is the offset/starting votes.

Production build 0.71.5 2024