Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
poll.module
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
9 Sep 2011 at 14:00 UTC
Updated:
4 Jan 2014 at 01:11 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
josevitalsoutoComment #2
josevitalsoutoThe choices also become disordered when clicked "More choices"
Comment #3
amateescu commented@vitalsouto, assigning issues to yourself means that you will work on (and create a patch for) them :)
Anyway, after I struggled a bit with FAPI, I found out that the problem lies in our call to
element_children()fromtheme_poll_choices().I will re-roll http://drupal.org/node/939880#comment-4941348 because reversing keys in
hook_validate()is not needed anymore after this patch.Comment #4
josevitalsoutoSorry, I'm still learning things here! :)
Comment #5
c31ck commentedPatch solved all above problems for me on Drupal 7.8. Thanks.
Comment #6
bleen commentedThis is the correct fix... RTBC
Comment #7
catchelement_children() defaults sorted to TRUE, so we need to explain why we're setting it to FALSE explicitly. Also this makes me wonder if there is somewhere earlier in the process it could be set to FALSE than the theme function? Why not in the form itself?
If that's already been rejected it'd be worth adding in a comment.
Lastly since we're using element_children() directly in the theme function, it'd be possible to use the $sort parameter to ensure these get sorted instead of the #sorted flag, don't have a preference though.
Comment #8
c31ck commentedShould we be using element_children in theme_poll_choices() to sort the poll choices? Can't we just add them in correct order in our form definition? When creating a new poll, the 2 choice inputs that are displayed have the same weight value. I created a patch that changes this.
Comment #9
c31ck commentedComment #10
amateescu commentedAfter a lot of thinking on this, I agree that increasing the weight for each choice is a good option as well, but should be done before adding the choice.
Our current tests don't catch this bug because in
_pollGenerateEdit()we specifically assign weights to new choices, and it's obvious that will always work :)The test-only patch attached removes the hardcoded weights and uncovers expected failures: the initial two choices are reversed. The commented test is intentional, because we're messing with weights in
poll_form()and that brings more failures than needed for the purpose of this test-only patch. Anyway, It's untouched in the full patch and it passes on my local dev.Comment #11
amateescu commentedTests behaved as expected, setting to RTBC based on the idea from #8 and because my patch only fixed the current tests.
Comment #12
catchLooks good. Committed/pushed to 8.x, moving back to 7.x for backport.
Comment #13
amateescu commented7.x patch.
Comment #14
josevitalsoutoComment #15
webchickCommitted and pushed to 7.x, thanks! Looks like a nice test clean-up as a bonus. :)
Comment #16
webchick