Problem/Motivation

There are several places in core where we need to sort an array by key, recursively (the recipe system has a usage of this, and a couple of tests do too) -- and there are instances in contrib where it's needed too (see #3550165: DefaultRelativeUrlPropSource does not sort properties keys for comparison, for example).

This would be useful for us to have generically.

Proposed resolution

Add a \Drupal\Component\Utility\SortArray::sortByKeyRecursive() method which does exactly what it says.

Issue fork drupal-3556987

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

phenaproxima created an issue. See original summary.

penyaskito’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Yes please. Tagging need tests.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Small unit test written.

fathershawn’s picture

Status: Needs review » Reviewed & tested by the community

That's a useful utility that consolidated several repetitions!

alexpott’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Nice - law threes - time for it to become API.

Committed and pushed 5071f112783 to 11.x and 13d4f6c1a39 to 11.3.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 13d4f6c1 on 11.3.x
    Issue #3556987 by phenaproxima, penyaskito, fathershawn: Add a recursive...

  • alexpott committed 5071f112 on 11.x
    Issue #3556987 by phenaproxima, penyaskito, fathershawn: Add a recursive...
wim leers’s picture

Nice!

Canvas already has 3 copies of that function, and is about to gain a 4th in #3550165: DefaultRelativeUrlPropSource does not sort properties keys for comparison — nice to see this land in core so quickly! 🥳

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.