I created a new vocabulary and i ordered the terms using the reset to alphabetical button. The problem is when clicking on the save button the order of the terms is set back to way it was before i reset the terms to alphabetical.

Steps to reproduce:
1. Create a vocabulary
2. Create terms. I created a,b,c for this case.
4. Order them by b, c, a
5. Click on reset to alphabetical button - the terms are arranged to a,b,c
6. Click on the save button
7. The terms are set back to b, c, a

This is also occur on 7.x branch.

Comments

roysegall’s picture

StatusFileSize
new26.34 KB
new33.28 KB
new32.96 KB

I adding some screenshots.
Before reset:
Before reset.png

After resetting to alphabetical:
After reset.png

After clicking on the save button, the order of the terms is set back to the way he was before the resetting:
After save.png

Now i can see that the save button set another ordering, but still this not the way it suppose to behave.

maciej.zgadzaj’s picture

Status: Active » Needs review
Issue tags: +Needs backport to D7
StatusFileSize
new1.81 KB

The issue comes from call to uasort($form_state['values'], 'drupal_sort_weight'); in taxonomy_overview_terms_submit().

Essentially, when Reset to alphabetical is used, all term weights are set to 0, and when they are passed to drupal_sort_weight() for sorting, due to PHP sorting functions not supporting stable sort after PHP 4.1.0, the results of such sort could be random. Which is even explained on usort page in PHP Manual:

If two members compare as equal, their relative order in the sorted array is undefined.

Attached patch fixes this issue, based on similar approach in module_config_sort() (although slightly improved).

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, drupal-taxonomy_reset_to_alphabetical-1913276-2.patch, failed testing.

maciej.zgadzaj’s picture

Status: Needs work » Needs review
Issue tags: +Needs backport to D7
hass’s picture

Sounds like a duplicate of another case.

roysegall’s picture

Didn't found like this.

I would be happy for a link to issue if there is one like this.

Status: Needs review » Needs work

The last submitted patch, drupal-taxonomy_reset_to_alphabetical-1913276-2.patch, failed testing.

maciej.zgadzaj’s picture

Status: Needs work » Closed (duplicate)

See comment #7.

gavin.hughes’s picture

Issue summary: View changes
StatusFileSize
new1.96 KB

I realised this issue is closed see #7 and its in progress and for back porting to drupal 7 not sure how that is best done. So
I was trying out patch in #2 it needed a re-roll for Drupal 7 site but it works! with a few warnings 'Illegal string offset Warning PHP'
So I tried to manage that a little :-)
Here is the re-rolled the patch for drupal 7 it may be of some help

misthero’s picture

patch #10 works!