Skip to content

Commit c782de3

Browse files
committed
Varianten und Kindknoten derselben Sortierung folgen lassen
getChildrenOfModel() holte die Kinder eines Knotens mit fest verdrahtetem "sorting ASC", waehrend die Wurzelebene ueber calculateRootConfig() die konfigurierte Sortierung nutzt und das Panel die gewaehlte darauf legt. In einem Baum, der nach einer Eigenschaft sortiert ist, standen die Elternknoten damit in der eingestellten Reihenfolge und ihre Kinder nicht. Sichtbar wird das bei den MetaModels-Varianten: die Basisdatensaetze alphabetisch, die Varianten darunter in Datenbankreihenfolge - siehe MetaModels/core#1395. Nachgemessen an einem Testmodell mit nach Namen sortierter Liste: vorher C, A, Z unter der Basis, jetzt A, C, Z. Uebernommen wird nur die Sortierung. Den Panel ueber den Kind-Config laufen zu lassen waere falsch, weil dessen Limit-Element Offset und Amount setzt - die Blaetterung der Liste landete damit auf den Kindern eines einzelnen Knotens. Fuer manuell sortierte Baeume aendert sich nichts: manuelle Sortierung loest auf die Eigenschaft "sorting" mit SORT_ASC auf und ergibt damit genau den Wert, der bisher fest im Code stand. Ohne jede Sortierung greift derselbe Rueckfall.
1 parent 2f803c9 commit c782de3

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/Controller/TreeCollector.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class TreeCollector implements EnvironmentAwareInterface
8181
*/
8282
private TreeNodeStates $states;
8383

84+
/**
85+
* The sorting that is effectively in use, cached for the whole tree walk.
86+
*
87+
* @var array<string, string>|null
88+
*/
89+
private ?array $effectiveSorting = null;
90+
8491
/**
8592
* Create a new instance.
8693
*
@@ -204,7 +211,7 @@ private function getChildrenOfModel(
204211
$children = $dataProvider->fetchAll(
205212
$dataProvider
206213
->getEmptyConfig()
207-
->setSorting(['sorting' => 'ASC'])
214+
->setSorting($this->getEffectiveSorting())
208215
->setFilter(
209216
FilterBuilder::fromArray()
210217
->getFilter()
@@ -335,6 +342,33 @@ private function addParentFilter(ConfigInterface $config, ModelInterface $parent
335342
}
336343
}
337344

345+
/**
346+
* Retrieve the sorting that the children of a node have to follow.
347+
*
348+
* Up to now the children were fetched with a hard coded "sorting ASC" while the root
349+
* level used the configured sorting. In a tree that is sorted by a property the parents
350+
* were therefore ordered as configured and their children were not - see
351+
* MetaModels/core#1395 for the variant lists this shows up in.
352+
*
353+
* Only the sorting is taken over from the root config. Handing the whole config or
354+
* running the panel over the child config would also apply the limit element and thus
355+
* put the pagination of the list onto the children of a single node.
356+
*
357+
* @return array<string, string>
358+
*/
359+
private function getEffectiveSorting(): array
360+
{
361+
if (null === $this->effectiveSorting) {
362+
$sorting = $this->calculateRootConfig()->getSorting();
363+
// Without any sorting the previous behaviour is kept. For a manually sorted tree
364+
// nothing changes either: manual sorting resolves to the property "sorting" with
365+
// SORT_ASC and therefore yields exactly the value that was hard coded before.
366+
$this->effectiveSorting = $sorting ?: ['sorting' => 'ASC'];
367+
}
368+
369+
return $this->effectiveSorting;
370+
}
371+
338372
/**
339373
* Put the base filter and sorting into a config.
340374
*

0 commit comments

Comments
 (0)