@@ -220,46 +220,30 @@ public function serializePaginated(array $serializedItems, PagerfantaInterface $
220220 public function serializeContentInterface (ContentInterface $ content , bool $ forceVisible = false ): mixed
221221 {
222222 $ toReturn = null ;
223- $ className = $ this ->entityManager ->getClassMetadata (\get_class ($ content ))->rootEntityName ;
224- switch ($ className ) {
225- case Entry::class:
226- /**
227- * @var Entry $content
228- */
229- $ dto = $ this ->entryFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfEntry ($ content ));
230- $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
231- $ toReturn = $ dto ->jsonSerialize ();
232- $ toReturn ['itemType ' ] = 'entry ' ;
233- break ;
234- case EntryComment::class:
235- /**
236- * @var EntryComment $content
237- */
238- $ dto = $ this ->entryCommentFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfEntryComment ($ content ));
239- $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
240- $ toReturn = $ dto ->jsonSerialize ();
241- $ toReturn ['itemType ' ] = 'entry_comment ' ;
242- break ;
243- case Post::class:
244- /**
245- * @var Post $content
246- */
247- $ dto = $ this ->postFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfPost ($ content ));
248- $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
249- $ toReturn = $ dto ->jsonSerialize ();
250- $ toReturn ['itemType ' ] = 'post ' ;
251- break ;
252- case PostComment::class:
253- /**
254- * @var PostComment $content
255- */
256- $ dto = $ this ->postCommentFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfPostComment ($ content ));
257- $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
258- $ toReturn = $ dto ->jsonSerialize ();
259- $ toReturn ['itemType ' ] = 'post_comment ' ;
260- break ;
261- default :
262- throw new \LogicException ('Invalid contentInterface classname " ' .$ className .'" ' );
223+ if ($ content instanceof Entry) {
224+ $ cross = $ this ->entryRepository ->findCross ($ content );
225+ $ crossDtos = array_map (fn ($ entry ) => $ this ->entryFactory ->createResponseDto ($ entry , []), $ cross );
226+ $ dto = $ this ->entryFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfEntry ($ content ), $ crossDtos );
227+ $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
228+ $ toReturn = $ dto ->jsonSerialize ();
229+ $ toReturn ['itemType ' ] = 'entry ' ;
230+ } elseif ($ content instanceof EntryComment) {
231+ $ dto = $ this ->entryCommentFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfEntryComment ($ content ));
232+ $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
233+ $ toReturn = $ dto ->jsonSerialize ();
234+ $ toReturn ['itemType ' ] = 'entry_comment ' ;
235+ } elseif ($ content instanceof Post) {
236+ $ dto = $ this ->postFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfPost ($ content ));
237+ $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
238+ $ toReturn = $ dto ->jsonSerialize ();
239+ $ toReturn ['itemType ' ] = 'post ' ;
240+ } elseif ($ content instanceof PostComment) {
241+ $ dto = $ this ->postCommentFactory ->createResponseDto ($ content , $ this ->tagLinkRepository ->getTagsOfPostComment ($ content ));
242+ $ dto ->visibility = $ forceVisible ? VisibilityInterface::VISIBILITY_VISIBLE : $ dto ->visibility ;
243+ $ toReturn = $ dto ->jsonSerialize ();
244+ $ toReturn ['itemType ' ] = 'post_comment ' ;
245+ } else {
246+ throw new \LogicException ('Invalid contentInterface classname " ' .$ this ->entityManager ->getClassMetadata (\get_class ($ content ))->rootEntityName .'" ' );
263247 }
264248
265249 if ($ forceVisible ) {
0 commit comments