- 🇫🇷France andypost
probably it could be added to @param description
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -128,8 +128,7 @@ public static function sortByKeyInt($a, $b, $key) { * Sorts a keyed array by weight and keys. ... - * The list is always sorted on write to avoid the overhead on read. + * Array values are supposed to be casted to integer as weights for keys. * * @param array $array * A keyed array of names with weight as value.
I think it makes sense to point about cast to in for array values
- 🇮🇳India Ratan Priya
@anypost,
Made changes as per comment #26.
Needs review. - Status changed to RTBC
over 1 year ago 4:46pm 20 March 2023 - Status changed to Needs work
over 1 year ago 9:30am 5 April 2023 - 🇬🇧United Kingdom alexpott 🇪🇺🌍
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,38 @@ public static function sortByKeyInt($a, $b, $key) { + /** + * Sorts a keyed array by weight and keys. + * + * @param array $array + * A keyed array of names with weight as value. + * Array values are supposed to be casted to integer as weights for keys. + * + * @return array + * An array sorted by weight and name. + * + * @internal + */ + public static function sortByWeightAndKeys(array $array): array {
If we're moving this functionality to the utility class we should be adding explicit and extensive test coverage of this to \Drupal\Tests\Component\Utility\SortArrayTest.
Also the name of this method is interesting I think it should be something else. The other usage of the word weight in this class refers to a weight property. Here we're sorting an array of integers by the value and then by the key. I think the method name should reflect that. To me this is really
sortByIntValueAndKey()
. I think the typehint should be@param int[] $array
. - 🇫🇷France andypost
Changed method name but still needs test.
Meanwhile I think we can remove this method at all in case of related 📌 Deprecate the trusted data concept in configuration Active
The new config class can care about sorting module list before saving the config if I got it right - Status changed to Needs review
over 1 year ago 1:58am 8 May 2023 21:23 19:21 Running- 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Added a test including one that I think should pass, but fails.
- last update
over 1 year ago 29,358 pass, 1 fail - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
For some reason the diff was whacky. Changing the order of methods seems to make it behave.
The last submitted patch, 31: 3262807-31.patch, failed testing. View results →
- 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php @@ -304,6 +304,77 @@ public function providerSortByTitleProperty() { + $tests['negative_weights'] = [ + [ + 'aaa' => -2, + 'bbb' => -1, + 'ccc' => -3, + ], + [ + 'bbb' => -3, + 'aaa' => -2, + 'ccc' => -1, + ], + ];
This should sort asc right?
The last submitted patch, 32: 3262807-32.patch, failed testing. View results →
- last update
over 1 year ago Build Successful - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
I think this can be greatly simplified to just an array multisort like:
array_multisort(array_values($array), SORT_ASC, array_keys($array), SORT_ASC, $array);
This modifies the original array that gets passed in by reference so calling code will need to change too. I think this is more in line with how usort etc. work though.
- Status changed to Needs work
over 1 year ago 1:18pm 8 May 2023 - 🇺🇸United States smustgrave
Seems to have some failures.
Have not re-reviewed yet.
- Status changed to Needs review
over 1 year ago 10:11pm 8 May 2023 - last update
over 1 year ago 29,362 pass, 12 fail - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Fixes test fails due to dodgy extension config setting logic.
- last update
over 1 year ago 29,382 pass, 8 fail - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Fix more extension config setting issues.
The last submitted patch, 38: 3262807-38.patch, failed testing. View results →
The last submitted patch, 39: 3262807-39.patch, failed testing. View results →
- last update
over 1 year ago 29,386 pass - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
I wonder if this should just be
sortByWeightAndKey()
since that's what we use it for? - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Just re-read the comments and @alexpott suggested
sortByIntValueAndKey()
back in #29. - 🇫🇷France andypost
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,15 @@ public static function sortByKeyInt($a, $b, $key) { + array_multisort(array_values($array), SORT_ASC, array_keys($array), SORT_ASC, $array);
Looking at https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/mig...
I think it should add SORT_NUMERIC to value and SORT_STRING to keys
- 🇫🇷France andypost
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,15 @@ public static function sortByKeyInt($a, $b, $key) { + * @param array $array + * key: (string) A key name. + * value: (int) A weight integer.
Missing "A Keyed array..."
- last update
over 1 year ago 29,386 pass - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
- last update
over 1 year ago 29,386 pass - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
More docblock feedback from @andypost in slack.
- Status changed to RTBC
over 1 year ago 9:02am 9 May 2023 - last update
over 1 year ago 29,389 pass - last update
over 1 year ago 29,394 pass 40:20 37:49 RunningThe last submitted patch, 48: 3262807-48.patch, failed testing. View results →
- Status changed to Needs work
over 1 year ago 8:28am 15 May 2023 - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Looks like a random fail. Happening in HEAD too apparently.
- Status changed to RTBC
over 1 year ago 9:59am 15 May 2023 - 🇫🇷France andypost
Yes, back to RTBC
Ref
Drupal\FunctionalTests\Installer\InstallerExistingConfigMultilingualTest
55:20 50:36 Running- 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
-
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php @@ -304,6 +304,89 @@ public function providerSortByTitleProperty() { + $tests['negative_weights_with_equal'] = [ + [ + 'bbb' => -1, + 'aaa' => -1, + 'ccc' => -3, + ], + [ + 'ccc' => -3,
Can we add a test case that uses a string value that is numeric e.g. '3'
-
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,16 @@ public static function sortByKeyInt($a, $b, $key) { + public static function sortByIntValueAndKey(array &$array): void { + array_multisort(array_values($array), SORT_ASC, SORT_NUMERIC, array_keys($array), SORT_ASC, SORT_NATURAL, $array);
Or alternatively can we add a check that each value is an integer?
-
- Status changed to Needs work
over 1 year ago 12:37am 18 May 2023 - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
Changing this to a bug as the current implementation doesn't correctly order negative weights.
- Status changed to Needs review
over 1 year ago 1:59am 19 May 2023 - Open on Drupal.org →Environment: PHP 8.2 & MySQL 8last update
over 1 year ago Waiting for branch to pass - 🇦🇺Australia kim.pepper 🏄♂️🇦🇺Sydney, Australia
#53.1
Added a test for passing string values (of numbers) that can still be sorted numerically.
- Status changed to RTBC
over 1 year ago 2:13am 19 May 2023 55:20 51:26 RunningThe last submitted patch, 56: 3262807-56.patch, failed testing. View results →
- Open on Drupal.org →Environment: PHP 8.2 & MySQL 8last update
over 1 year ago Waiting for branch to pass - last update
over 1 year ago 29,404 pass - last update
over 1 year ago 29,408 pass - last update
over 1 year ago 29,408 pass - last update
over 1 year ago 29,409 pass - last update
over 1 year ago 29,409 pass - last update
over 1 year ago 29,418 pass - last update
over 1 year ago 29,401 pass, 2 fail The last submitted patch, 56: 3262807-56.patch, failed testing. View results →
- last update
over 1 year ago 29,424 pass 40:20 43:05 Running- last update
over 1 year ago 29,444 pass - last update
over 1 year ago 29,444 pass - last update
over 1 year ago 29,452 pass - last update
over 1 year ago 29,480 pass - last update
over 1 year ago 29,506 pass - last update
over 1 year ago 29,506 pass - last update
over 1 year ago 29,538 pass - last update
over 1 year ago 29,560 pass - last update
over 1 year ago 29,561 pass - last update
over 1 year ago 29,569 pass - last update
over 1 year ago 29,573 pass - last update
over 1 year ago 29,578 pass - last update
over 1 year ago 29,808 pass - last update
over 1 year ago 29,809 pass - last update
over 1 year ago 29,809 pass - last update
over 1 year ago 29,812 pass - last update
over 1 year ago 29,818 pass - last update
over 1 year ago 29,821 pass - last update
over 1 year ago 29,822 pass - last update
over 1 year ago 29,826 pass, 1 fail The last submitted patch, 56: 3262807-56.patch, failed testing. View results →
- 🇺🇸United States smustgrave
Seems like the random failure popping up today.
- last update
over 1 year ago 29,834 pass - last update
over 1 year ago 29,886 pass - last update
over 1 year ago 29,886 pass - last update
over 1 year ago 29,891 pass - last update
over 1 year ago 29,894 pass - last update
over 1 year ago 29,915 pass - last update
over 1 year ago 29,953 pass - last update
over 1 year ago 29,952 pass, 2 fail The last submitted patch, 56: 3262807-56.patch, failed testing. View results →
- last update
over 1 year ago 29,953 pass - Status changed to Needs work
over 1 year ago 6:57am 4 August 2023 - 🇫🇷France andypost
failed
Drupal\Tests\views\Functional\Plugin\DisplayFeedTranslationTest::testFeedFieldOutput()
, re-queued - Status changed to RTBC
over 1 year ago 4:46am 29 August 2023 - last update
over 1 year ago 30,067 pass - last update
over 1 year ago 30,107 pass - last update
over 1 year ago 30,142 pass - last update
over 1 year ago 30,142 pass - last update
over 1 year ago 30,143 pass - last update
over 1 year ago 30,153 pass - last update
over 1 year ago 30,153 pass - last update
over 1 year ago 30,155 pass - last update
over 1 year ago 27,759 pass, 836 fail The last submitted patch, 56: 3262807-56.patch, failed testing. View results →
- last update
over 1 year ago Build Successful - 🇫🇷France andypost
Failures after 🐛 Strengthen TransactionManager Needs work
- last update
over 1 year ago 30,168 pass - last update
about 1 year ago 30,171 pass - last update
about 1 year ago 30,175 pass - last update
about 1 year ago 30,212 pass - last update
about 1 year ago Build Successful - last update
about 1 year ago 30,370 pass - last update
about 1 year ago 30,368 pass - last update
about 1 year ago 30,367 pass - last update
about 1 year ago 30,378 pass - last update
about 1 year ago 30,386 pass - last update
about 1 year ago 30,384 pass - last update
about 1 year ago 30,389 pass - last update
about 1 year ago 30,399 pass - Status changed to Needs review
about 1 year ago 1:15am 12 October 2023 - last update
about 1 year ago 30,401 pass - 🇳🇿New Zealand quietone
I'm triaging RTBC issues → . I read the IS and the comments. I didn't find any unanswered questions or other work to do.
I noted that #53 suggesting either testing for an integer or testing for numeric. I read the patch and it adds a test for numeric values proving that the method works for integer and numeric values. However, the method name is still,
sortByIntValueAndKey
, which seems misleading. Shouldn't it besortByNumericValueAndKey
? Although, I guess one could also argue that is should 'Natural' should be in the title as well.-
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,16 @@ public static function sortByKeyInt($a, $b, $key) { + * Sorts an associative array by int value then key.
"int" is not a word. But this also accepts numeric values.
-
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,16 @@ public static function sortByKeyInt($a, $b, $key) { + * - value: An integer.
The tests include testing numeric values, so is this correct?
-
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php @@ -304,6 +304,101 @@ public function providerSortByTitleProperty() { + * An array of tests, matching the parameter inputs for + * sortByIntValueAndKey.
This is rather generic, merely describing what any data provider does. I suppose the test should have a case for alphanumeric keys.
Instead of setting back to NW I opted to make a patch changing the method name and updating the comments. Is this better?
-
- 🇫🇷France andypost
Good point about numeric, the only question is a test for floats (as they allowed)
doc-block is fine to keep with
int
+++ b/core/lib/Drupal/Component/Utility/SortArray.php @@ -125,4 +125,16 @@ public static function sortByKeyInt($a, $b, $key) { + * Sorts an associative array by numeric value then key. + * + * @param int[] $array + * An associative array containing: + * - key: A string. + * - value: A numeric value. + */ + public static function sortByNumericValueAndKey(array &$array): void { + array_multisort(array_values($array), SORT_ASC, SORT_NUMERIC, array_keys($array), SORT_ASC, SORT_NATURAL, $array);
There's no ability to point (int|float)[]
- 🇺🇸United States smustgrave
Is it something that should be allowed? Would it be worth a follow up to look into disallowing or throwing an error if floats are passed?
- Status changed to RTBC
about 1 year ago 7:59pm 20 October 2023 - 🇺🇸United States smustgrave
Going to mark but do wonder if we should prevent floats.
- last update
about 1 year ago 30,433 pass - last update
about 1 year ago 30,434 pass - Status changed to Needs work
about 1 year ago 11:41am 24 October 2023 - 🇬🇧United Kingdom longwave UK
I think it's fine to document that the values should be integers; if it coincidentally works with floats that is not something we officially support as we have not documented it, but also something that I don't think we should spend time checking for or throwing errors for.
The updated method name has not been correctly replaced in all places, such as comments and the deprecation notice, back to NW for that.
Assigned and saved issue credits.
- 🇬🇧United Kingdom longwave UK
-
+++ b/core/includes/module.inc @@ -104,8 +109,14 @@ function module_set_weight($module, $weight) { + * \Drupal\Component\Utility\SortArray::sortByIntValueAndKey() instead.
Method name needs updating.
-
+++ b/core/includes/module.inc @@ -104,8 +109,14 @@ function module_set_weight($module, $weight) { + @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Utility\SortArray::sortByIntValueAndKey() instead. See https://www.drupal.org/node/3262814', E_USER_DEPRECATED);
Method name needs updating.
-
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php @@ -304,6 +304,114 @@ public function providerSortByTitleProperty() { + * @dataProvider providerSortByIntValueAndKey ... + public function testSortByIntValueAndKey(array $a, array $expected): void { ... + * Data provider for SortArray::sortByIntValueAndKey(). ... + * @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByIntValueAndKey() ... + public function providerSortByIntValueAndKey(): array {
Method names need updating.
-
- last update
about 1 year ago 30,442 pass - Status changed to Needs review
about 1 year ago 2:37pm 24 October 2023 - Status changed to Needs work
about 1 year ago 4:44pm 24 October 2023 - 🇺🇸United States smustgrave
Could it be as simple as
value: A numeric value. Recommended to use integer values, floats will work but not supported
?
- last update
about 1 year ago 30,444 pass - Status changed to Needs review
about 1 year ago 12:36am 25 October 2023 - Status changed to RTBC
about 1 year ago 1:34am 25 October 2023 - last update
about 1 year ago 30,445 pass - last update
about 1 year ago 30,449 pass - last update
about 1 year ago 30,472 pass - last update
about 1 year ago 30,488 pass - last update
about 1 year ago 30,493 pass - last update
about 1 year ago 30,494 pass - last update
about 1 year ago 30,496 pass - last update
about 1 year ago 30,518 pass - last update
about 1 year ago 30,524 pass - last update
about 1 year ago 30,528 pass - last update
about 1 year ago 30,539 pass - 🇺🇸United States xjm
Please remember to hide patch files from the IS when an issue is converted to MR. Thanks!
- Status changed to Needs work
about 1 year ago 3:43pm 16 November 2023 - 🇺🇸United States xjm
Posted a number of points on the MR. I have several concerns about the data typing and integrity as well as possible behavior changes from this deprecation.
This will need config subsystem maintainer signoff before it is committed. It is also a significant change that may impact the data integrity of the config sort if done incorrectly, so it should have careful committer review in its final state.