@@ -42,6 +42,9 @@ public function main(Result $result, array $templates, Translator $translator):
4242 $ selectedTemplates = $ this ->selectTemplates ($ result , $ templates );
4343 if (!$ this ->isFinalTemplate ($ result , $ selectedTemplates )) {
4444 foreach ($ this ->extractDeduplicatedChildren ($ result ) as $ child ) {
45+ if ($ result ->path !== null && $ child ->path !== null ) {
46+ $ child = $ child ->withPath (sprintf ('%s.%s ' , $ result ->path , $ child ->path ));
47+ }
4548 return $ this ->main ($ child , $ selectedTemplates , $ translator );
4649 }
4750 }
@@ -99,35 +102,46 @@ public function array(Result $result, array $templates, Translator $translator):
99102 {
100103 $ selectedTemplates = $ this ->selectTemplates ($ result , $ templates );
101104 $ messages = [
102- '__root ' => $ this ->renderer ->render ($ this ->getTemplated ($ result , $ selectedTemplates ), $ translator ),
105+ '_self ' => [
106+ $ result ->id => $ this ->renderer ->render ($ this ->getTemplated ($ result , $ selectedTemplates ), $ translator )
107+ ],
108+ '_children ' => []
103109 ];
104-
105- $ children = [];
106110 foreach ($ this ->extractDeduplicatedChildren ($ result ) as $ child ) {
111+
112+ if ($ child ->path === null ) {
113+ $ messages ['_self ' ][$ child ->id ] = $ this ->renderer ->render ($ this ->getTemplated ($ child , $ selectedTemplates ), $ translator );
114+ continue ;
115+ }
107116 $ childKey = $ child ->path ?? '__ ' . $ child ->id ;
108117
109- $ children [$ childKey ] = $ this ->array (
118+ $ messages [ ' _children ' ] [$ childKey ] = $ this ->array (
110119 $ child ,
111120 $ this ->selectTemplates ($ child , $ selectedTemplates ),
112121 $ translator
113122 );
114123
115- if (count ($ children [$ childKey ]) !== 1 ) {
124+ if (count ($ messages [ ' _children ' ] [$ childKey ]) !== 1 ) {
116125 continue ;
117126 }
118127
119- $ children [ $ childKey ] = current ($ children [$ childKey ]);
128+ $ messages [ ' _children ' ][ $ childKey ] = current ($ messages [ ' _children ' ] [$ childKey ]);
120129 }
121130
122- if (count ($ children ) === 0 || $ this ->isFinalTemplate ($ result , $ selectedTemplates )) {
123- return [$ result ->path ?? '__ ' . $ result ->id => $ messages ['__root ' ]];
131+ // if (count($messages['_children']) === 0 || $this->isFinalTemplate($result, $selectedTemplates)) {
132+ // return [$result->path ?? '__' . $result->id => $messages['__root']];
133+ // }
134+ //
135+
136+ if ($ messages ['_children ' ] === []) {
137+ unset($ messages ['_children ' ]);
124138 }
125139
126140 if ($ result ->path !== null ) {
127- return [$ result ->path => $ messages + $ children ];
141+ return [$ result ->path => $ messages ];
128142 }
129143
130- return $ messages + $ children ;
144+ return $ messages; // + $messages['_children'] ;
131145 }
132146
133147 private function isAlwaysVisible (Result $ result , Result ...$ siblings ): bool
@@ -241,12 +255,18 @@ private function extractDeduplicatedChildren(Result $result): array
241255 if (isset ($ duplicateCounters [$ id ])) {
242256 $ id .= '. ' . ++$ duplicateCounters [$ id ];
243257 } elseif (array_key_exists ($ id , $ deduplicatedResults )) {
244- $ deduplicatedResults [$ id . '.1 ' ] = $ deduplicatedResults [$ id ]?->withId($ id . '.1 ' );
258+ $ deduplicatedResults [$ id . '.1 ' ] = $ child ->path
259+ ? $ deduplicatedResults [$ id ]?->withPath($ id . '.1 ' )
260+ : $ deduplicatedResults [$ id ]?->withId($ id . '.1 ' );
245261 unset($ deduplicatedResults [$ id ]);
246262 $ duplicateCounters [$ id ] = 2 ;
247263 $ id .= '.2 ' ;
248264 }
249- $ deduplicatedResults [$ id ] = $ child ->isValid ? null : $ child ->withId ((string ) $ id );
265+ $ deduplicatedResults [$ id ] = $ child ->isValid ? null : (
266+ $ child ->path
267+ ? $ child ->withPath ((string ) $ id )
268+ : $ child ->withId ((string ) $ id )
269+ );
250270 }
251271
252272 return array_values (array_filter ($ deduplicatedResults ));
0 commit comments