Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort order for di.xml arrays can't be influenced #1379

Closed
Vinai opened this issue Jun 17, 2015 · 2 comments
Closed

Sort order for di.xml arrays can't be influenced #1379

Vinai opened this issue Jun 17, 2015 · 2 comments

Comments

@Vinai
Copy link
Contributor

Vinai commented Jun 17, 2015

When constructing arrays using DI (or also in layout XML) with the array type, it seems to be impossible to influence the order or the elements except via module load sequence.
However, it currently is not possible to have one module to add itself to the sequence of another module, which limits this option severely.
As I'm sure you are aware, the sort order of the array elements can be quite important.

In some instances, for example the RouterList, this problem is overcome by making each router in the list a sub-array with the possibility to add a sortOrder. This works fine, but if the injected array is one dimensional it isn't an option. It forces the structure onto the client receiving the array.

In other cases the injected list is simply an array of objects or strings, without the chance to influence the sort order.
One example is the composite phrase renderer. It isn't possible to add a renderer before the placeholder renderer.

It would be quite useful to be able to add an optional sortOrder attribute to the item node, which - if present - is used to sort the resulting array argument.
Maybe a before/after attribute (like in layout XML) would be more appropriate, but I'm sure opinions on this will vary. Personally I don't care, I would simply like to have an option to influence the sort order of dependency injected arrays built with in di.xml, without resorting to changing the module load sequence.

@antonkril
Copy link
Contributor

Sorting wasn't implemented because it'll have impact on performance of ObjectManager. But I agree that we should support it. Thanks for the suggestion. I'll let you know when we have news about this.

@piotrekkaminski
Copy link
Contributor

Thank you for your submission.

We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues.

Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here).

We are closing this GitHub ticket and have moved your request to the new forum.

magento-team pushed a commit that referenced this issue Aug 3, 2017
…-2.3-merge

[jackalopes] MAGETWO-71255: merge 2.2 in 2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants