Feature request from Vinai, posted on GitHub 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
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.