Apply changes on #3165828 and adjust param type in function comment.
This merge request is applying the changes on this patch file (https://www.drupal.org/files/issues/2024-01-04/sort_by_weight_3165828_7.patch), as well as fixing the param types in sortByWeight
function comment.
Closes #3165828