public static function onPostCategoryCall(Event $event) { $response = $event->getResponse(); $entityManager = $event->getApplication()->getEntityManager(); $user = $event->getApplication()->getBBUserToken()->getUser(); $favoriteCategory = self::getFavoriteCategory($entityManager, $user->getId()); if (empty($favoriteCategory['contents'])) { $favoriteCategory = self::getDefaultFavoriteCategory($entityManager, $event->getApplication()->getSite()->getUid(), $favoriteCategory); } $categories = json_decode($response->getContent(), true); /* the new category has been pushed on top of class content categories */ array_unshift($categories, $favoriteCategory); $response->setContent(json_encode($categories, true)); }
public static function onPostCall(Event $event) { $response = $event->getResponse(); if ($response->headers->get('content-type') === 'text/html') { return; } $application = $event->getApplication(); $renderer = $application->getRenderer(); $content = json_decode($response->getContent()); $result = false; if ($content instanceof \StdClass) { if (isset($content->type) && isset($content->parameters)) { if (isset($content->parameters->rendermode)) { $result = true; } } } if (!$result) { return; } $rendermodeParam = $content->parameters->rendermode; $classname = AbstractClassContent::getClassnameByContentType($content->type); $modes = ['default' => 'Default mode']; foreach ($renderer->getAvailableRenderMode(new $classname()) as $mode) { $modes[$mode] = ucfirst(str_replace('_', ' ', $mode)); } $rendermodeParam->options = $modes; $response->setContent(json_encode($content)); }