Problem
When editing an existing poll node and adding another option, the new option appears at the top instead of at the bottom when viewing the node. The weight for the new option is not getting saved. Any value entered in the vote count column for the new option isn't saved either.
Steps to reproduce:
- Create a poll node with 2 choices.
- Save the poll.
- Edit the poll and add a third choice.
- Save the poll.
You will notice that the third option you just entered appears at the top of the list of choices, not at the bottom. If you've entered a value in the show count field, this value isn't saved either.
I don't think this bug is related to #1274212.
Proposed resolution
Change the db_merge query. In node.module line 579:
foreach ($node->choice as $key => $choice) {
if (!empty($choice['chtext'])) {
db_merge('poll_choice')
->key(array('chid' => $choice['chid']))
->fields(array(
'nid' => $node->nid,
'chtext' => $choice['chtext'],
'chvotes' => (int) $choice['chvotes'],
'weight' => $choice['weight'],
))
->execute();
}
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | poll-order-1295546-D7-15.patch | 1.64 KB | amateescu |
| #15 | poll-order-1295546-15.patch | 1.68 KB | amateescu |
| #15 | poll-order-1295546-15-D7.patch | 1.64 KB | amateescu |
| #14 | poll-order-1295546-14.patch | 1.55 KB | xjm |
| #13 | poll-order-1295546.patch | 1.51 KB | marcingy |
Comments
Comment #1
c31ck commentedPatch that implements the fix suggested above.
Comment #2
amateescu commentedHave you tried the patch from #1274212-3: Incorrect order of choices in Poll module.?
Comment #3
c31ck commentedYes, I tried that patch but it did not resolve the problem.
Comment #4
marcingy commentedThis is still a duplicate of #1274212: Incorrect order of choices in Poll module. all discussion should be kept in one place.
Comment #5
marcingy commentedActually maybe not after reread the other issue for a 3rd time - my bad sorry
Comment #6
c31ck commentedAfter having another look at the query it occurred to me that the chvotes value isn't getting saved either. Changing the title of this issue accordingly.
Comment #7
c31ck commentedPatch that fixes both the weight and the vote count not beeing saved.
Comment #8
marcingy commentedThe patch in #7 does not work for me as it remains with ordering issues.
Comment #9
c31ck commentedBoth patch #7 and #8 work fine for me. Could you describe what exactly isn't working in patch #7?
Comment #10
marcingy commentedIn #7 the sort order still do not stay fixed and it was also failing tests.
Comment #11
c31ck commentedAfter having another look I agree that adding the weight and chvotes field to the insertFields method is the correct way to fix this.
Comment #12
webchickLet's get a test added for this. And I assume this applies to D7 too since I'm not aware of any major improvements in Poll module in D8. :)
Comment #13
marcingy commentedNew patch with a test to ensure order is maintained and poll votes are saved when an update is performed.
Comment #14
xjmRerolled for core/.
Comment #15
amateescu commentedSmall re-roll for some spacing issues and changing the order of:
Other than that, looks ready to me. Attached a patch for D7 too.
4 days to next Drupal core point release.
Comment #16
catchLooks good. Committed/pushed to 8.x, moving to 7.x - there's already a patch here, but it needs the bot to run it.
Comment #17
amateescu commentedRe-uploading the patch from #15 for the testbot.
Comment #18
amateescu commentedLooking good, back to RTBC.
Comment #19
webchickCommitted and pushed to 7.x. Thanks!
Comment #20.0
(not verified) commentedAdded votes count bug information.