@@ -28,6 +28,7 @@ class WhatNowEntityTransformer extends TransformerAbstract
2828 * @param WhatNowTranslationRepositoryInterface $repo
2929 * @param array $configuration
3030 */
31+
3132 function __construct (WhatNowTranslationRepositoryInterface $ repo , $ configuration = [])
3233 {
3334 if (isset ($ configuration ['unpublished ' ]) && is_bool ($ configuration ['unpublished ' ])) {
@@ -70,7 +71,7 @@ public function transform(WhatNowEntity $model)
7071 'url ' => $ model ->organisation ->attribution_url ,
7172 'imageUrl ' => $ model ->organisation ->attribution_file_name ? $ model ->organisation ->getAttributionImageUrl () : null ,
7273 'translations ' => null
73- ]
74+ ],
7475 ];
7576
7677 if ($ model ->organisation ->details ->count ()) {
@@ -88,7 +89,7 @@ public function transform(WhatNowEntity $model)
8889 }
8990
9091 if ($ this ->unpublished ) {
91- $ translations = $ this ->wnTransRepo ->getLatestTranslations ($ model ->id );
92+ $ translations = $ this ->wnTransRepo ->getLatestTranslations ($ model ->id ) ?? [] ;
9293 } else {
9394 $ translations = $ this ->wnTransRepo ->getLatestPublishedTranslations ($ model ->id , $ this ->lang );
9495 }
@@ -99,14 +100,28 @@ public function transform(WhatNowEntity $model)
99100 }
100101
101102 if ($ translations ) {
102-
103+ $ response [ ' translations ' ] = [];
103104 /** @var WhatNowEntityTranslation $trans */
104105 foreach ($ translations as $ trans ) {
105106
106107 $ stages = $ defaultStages ;
107108 if ($ trans ->stages ){
108109 foreach ($ trans ->stages as $ stage ) {
109- $ stages [$ stage ->stage ] = json_decode ($ stage ['content ' ]);
110+ $ stage ->load ('keyMessages ' );
111+ $ keyMessages = $ stage ->keyMessages ;
112+
113+ foreach ($ keyMessages as $ keyMessage ) {
114+ $ keyMessage ->load ('supportingMessages ' );
115+ }
116+
117+ $ stages [$ stage ->stage ] = $ keyMessages ->map (function ($ keyMessage ) {
118+ return [
119+ 'title ' => $ keyMessage ->title ,
120+ 'content ' => $ keyMessage ->supportingMessages ->map (function ($ supportingMessage ) {
121+ return $ supportingMessage ->content ;
122+ })->toArray ()
123+ ];
124+ })->toArray ();
110125 }
111126 }
112127
0 commit comments