diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php index 608e714..959df68 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Form; +use Drupal\Component\Utility\SortArray; use Drupal\Core\Form\FormBase; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\taxonomy\VocabularyInterface; @@ -23,11 +24,6 @@ class OverviewTerms extends FormBase { * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; - - /** - * The current orders. - */ - protected $current_order; /** * Constructs an OverviewTerms object. @@ -372,21 +368,24 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ * An associative array containing the current state of the form. */ public function submitForm(array &$form, array &$form_state) { - //Sort terms based on weight and on the current order in which they are - //displayed on the page. - $this->current_order = 0; + // Mark each term with the current order in which they are displayed in the + // form. + $current_order = 0; foreach ($form_state['values'] as $tid => &$value) { if (isset($form[$tid]['#term'])) { $value['current_order'] = $current_order++; } } - uasort($form_state['values'], 'taxonomy_overview_sort'); - // Clean up. - foreach ($form_state['values'] as $tid => &$value) { - if (isset($form[$tid]['#term'])) { - unset($value['current_order']); + + // Sort terms, first on weight, second on the current order. + uasort($form_state['values'], function ($a, $b) { + // If the terms have different weights, sort by weight. + if ($result = \Drupal\Component\Utility\SortArray::sortByWeightElement((array) $a, (array) $b)) { + return $result; } - }; + // If the weights are identical, sort by the current order. + return \Drupal\Component\Utility\SortArray::sortByKeyInt($a, $b, 'current_order'); + }); $vocabulary = $form_state['taxonomy']['vocabulary']; // Update the current hierarchy type as we go. @@ -472,5 +471,5 @@ public function submitForm(array &$form, array &$form_state) { public function submitReset(array &$form, array &$form_state) { $form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $form_state['taxonomy']['vocabulary']->id() . '/reset'; } - + } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 717f569..81537b6 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1178,34 +1178,6 @@ function taxonomy_taxonomy_term_delete(Term $term) { } /** - * Sorts a structured array by the 'weight' and 'current_order' elements. - * - * Callback for uasort() within taxonomy_overview_terms_submit(). - * - * @param $a - * First item for comparison. The compared items should be associative arrays - * that optionally include 'weight' or 'current_order' elements. If these - * elements are missing, a default value of 0 will be used. - * @param $b - * Second item for comparison. - */ -function taxonomy_overview_sort($a, $b) { - // First try to sort by the defined weight. - if ($result = \Drupal\Component\Utility\SortArray::sortByWeightElement((array) $a, (array) $b)) { - return $result; - } - // If the weights match, sort by the current order instead. - $a_order = (is_array($a) && isset($a['current_order'])) ? $a['current_order'] : 0; - $b_order = (is_array($b) && isset($b['current_order'])) ? $b['current_order'] : 0; - if ($a_order == $b_order) { - return 0; - } - return ($a_order < $b_order) ? -1 : 1; -} - - - -/** * @} End of "defgroup taxonomy_index". */