Commit 6f3e437f authored by webchick's avatar webchick

Issue #2029537 by Xano, InternetDevels, -enzo- | tsphethean: Replace...

Issue #2029537 by Xano, InternetDevels, -enzo- | tsphethean: Replace drupal_sort_weight() with SortArray::sortByWeightElement() and remove drupal_sort_weight().
parent 6e8c9253
......@@ -4683,32 +4683,6 @@ function element_info_property($type, $property_name, $default = NULL) {
return (($info = element_info($type)) && array_key_exists($property_name, $info)) ? $info[$property_name] : $default;
}
/**
* Sorts a structured array by the 'weight' element.
*
* Note that the sorting is by the 'weight' array element, not by the render
* element property '#weight'.
*
* Callback for uasort() used in various functions.
*
* @param $a
* First item for comparison. The compared items should be associative arrays
* that optionally include a 'weight' element. For items without a 'weight'
* element, a default value of 0 will be used.
* @param $b
* Second item for comparison.
*
* @return int
* The comparison result for uasort().
*
* @see \Drupal\Component\Utility\SortArray::sortByWeightElement()
*
* @deprecated as of Drupal 8.0. Use SortArray::sortByWeightElement() instead.
*/
function drupal_sort_weight($a, $b) {
return SortArray::sortByWeightElement((array) $a, (array) $b);
}
/**
* Sorts a structured array by 'title' key (no # prefix).
*
......@@ -5138,7 +5112,7 @@ function drupal_get_updaters() {
if (!isset($updaters)) {
$updaters = \Drupal::moduleHandler()->invokeAll('updater_info');
drupal_alter('updater_info', $updaters);
uasort($updaters, 'drupal_sort_weight');
uasort($updaters, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
}
return $updaters;
}
......@@ -5158,7 +5132,7 @@ function drupal_get_filetransfer_info() {
if (!isset($info)) {
$info = \Drupal::moduleHandler()->invokeAll('filetransfer_info');
drupal_alter('filetransfer_info', $info);
uasort($info, 'drupal_sort_weight');
uasort($info, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
}
return $info;
}
......
......@@ -1067,7 +1067,7 @@ function update_resolve_dependencies($starting_updates) {
// Perform the depth-first search and sort on the results.
$graph_object = new Graph($graph);
$graph = $graph_object->searchAndSort();
uasort($graph, 'drupal_sort_weight');
uasort($graph, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
foreach ($graph as $function => &$data) {
$module = $data['module'];
......
......@@ -160,7 +160,7 @@ public function buildOperations(EntityInterface $entity) {
// Retrieve and sort operations.
$operations = $this->getOperations($entity);
$this->moduleHandler()->alter('entity_operation', $operations, $entity);
uasort($operations, 'drupal_sort_weight');
uasort($operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$build = array(
'#type' => 'operations',
'#links' => $operations,
......
......@@ -171,7 +171,7 @@ public function getOptions($field_type = NULL) {
$options = array();
$field_types = $this->fieldTypeManager->getDefinitions();
$widget_types = $this->getDefinitions();
uasort($widget_types, 'drupal_sort_weight');
uasort($widget_types, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
foreach ($widget_types as $name => $widget_type) {
foreach ($widget_type['field_types'] as $widget_field_type) {
// Check that the field type exists.
......
......@@ -75,7 +75,7 @@ function testList() {
$actual_operations = $controller->getOperations($entity);
// Sort the operations to normalize link order.
uasort($actual_operations, 'drupal_sort_weight');
uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.');
// Test buildHeader() method.
......@@ -148,7 +148,7 @@ function testList() {
$actual_operations = $controller->getOperations($entity);
// Sort the operations to normalize link order.
uasort($actual_operations, 'drupal_sort_weight');
uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.');
}
......
......@@ -61,7 +61,7 @@ public function getInstance(array $options) {
$selection_handler_groups = $this->getSelectionGroups($target_entity_type);
// Sort the selection plugins by weight and select the best match.
uasort($selection_handler_groups[$selection_handler], 'drupal_sort_weight');
uasort($selection_handler_groups[$selection_handler], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
end($selection_handler_groups[$selection_handler]);
$plugin_id = key($selection_handler_groups[$selection_handler]);
......
......@@ -240,7 +240,7 @@ public function reduceOrder($array, $a) {
$array[] = $a['name'];
}
if (!empty($a['children'])) {
uasort($a['children'], 'drupal_sort_weight');
uasort($a['children'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$array = array_merge($array, array_reduce($a['children'], array($this, 'reduceOrder')));
}
return $array;
......
......@@ -370,7 +370,7 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $
*/
public function submitForm(array &$form, array &$form_state) {
// Sort term order based on weight.
uasort($form_state['values']['terms'], 'drupal_sort_weight');
uasort($form_state['values']['terms'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
$vocabulary = $form_state['taxonomy']['vocabulary'];
// Update the current hierarchy type as we go.
......
......@@ -665,7 +665,7 @@ protected function buildGroupValidate($form, &$form_state) {
*/
protected function buildGroupSubmit($form, &$form_state) {
$groups = array();
uasort($form_state['values']['options']['group_info']['group_items'], 'drupal_sort_weight');
uasort($form_state['values']['options']['group_info']['group_items'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
// Filter out removed items.
// Start from 1 to avoid problems with #default_value in the widget.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment