Fluid
Fluid copied to clipboard
[FEATURE] groupedFor with sorting
Currently there seems to be a lack of functionality when grouped records in the view have to be sorted. defaultSorting for repositories do not intervene.
Use case:
Need to sorting records grouped by f:groupedFor ViewHelper by groupBy property. In case the groupyByproperty is an object that itself brings "sorting" column.
- Record with category property
- Category has sorting property
- Records are grouped in view with f:groupedFor
- Sorting of grouped records should be based on Category property
Hi Felix - this one looks like it goes beyond the iterator-like behavior of f:for and f:groupedFor, and implementing it would imply a lot of other "lacks of functionality" - for example, needing to specify the sorting direction, the sorting flags and so on, and it doesn't work too well with the fact that we would need these sorters to be somewhat advanced (extracting values in ways appropriate not just for Fluid but potential third party VariableProviders like TYPO3 CMS has).
This is off the top of my head, but it seems bad practice to implement this fairly significant number of arguments that would be required, in multiple ViewHelpers. For example, should f:for also support it? Should f:cycle? And so on.
The first recommendation would be to sort this ahead of passing it to the View. That's always the best approach. As a secondary option things like the Iterator ViewHelpers from VHS would make sense (letting you sort arrays/Iterators inside the View before/after groupedFor or other iterations), but in order to be effective, that collection pretty much needs to be available in full.
Work is being done on creating a separate ViewHelper package that you could add as composer dependency to gain access to a lot of advanced, but not regular-use-case type ViewHelpers which among other things would do sorting. But as a feature native to Fluid I tend to reject this for the reasons above.
Has relation to discussion at https://forge.typo3.org/issues/78527, namely the presence of the reverse argument on f:for and the possibility that this will be deprecated.
One thing to add here is that the output of f:groupedFor can be different for each frontend language, if the sorting feature cannot be set.
Sorting this before the view, makes this viewhelper obsolete.
Hey.
I'd argue special sorting (like reverse, or by some key or collation) should be specefic VH's. This avoids implementing complex stuff into GroupedFor and others. When there are general sorting things, Fluid should provide, we could add them as dedicated view helpers to the system. Feel free to go ahead in this area. We'll close the issue since we won't add such options to groupedFor, though.