public function viewAction(Request $request, $id, $structure = 'tree')
    {
        $response = new JsonResponse();

        /** @var ContentRepository $contentRepository */
        $contentRepository = $this->get('opifer.content.content_manager')->getRepository();
        $content = $contentRepository->findOneByIdOrSlug($id, true);
        if ($content->getSlug() === '404') {
            // If the original content was not found and the 404 page was returned, set the correct status code
            $response->setStatusCode(404);
        }

        $version = $request->query->get('_version');
        $debug = $this->getParameter('kernel.debug');

        $response->setLastModified($content->getLastUpdateDate());
        $response->setPublic();

        if (null === $version && false == $debug && $response->isNotModified($request)) {
            // return the 304 Response immediately
            return $response;
        }

        /** @var Environment $environment */
        $environment = $this->get('opifer.content.block_environment');
        $environment->setObject($content);

        if (null !== $version && $this->isGranted('ROLE_ADMIN')) {
            $environment->setDraft(true);
        }

        $environment->load();

        $context = SerializationContext::create()
            ->addExclusionStrategy(new BlockExclusionStrategy($content))
            // ->setGroups(['Default', 'detail'])
        ;

        if ($structure == 'tree') {
            $blocks = $environment->getRootBlocks();
            $context->setGroups(['Default', 'tree', 'detail']);
        } else {
            $blocks = $environment->getBlocks();
            $context->setGroups(['Default', 'detail'])
                ->enableMaxDepthChecks();
        }

        $contentItem = [
            'id' => $content->getId(),
            'created_at' => $content->getCreatedAt(),
            'updated_at' => $content->getUpdatedAt(),
            'published_at' => $content->getPublishAt(),
            'title' => $content->getTitle(),
            'shortTitle' => $content->getShortTitle(),
            'description' => $content->getDescription(),
            'slug' => $content->getSlug(),
            'alias' => $content->getAlias(),
            'blocks' => $blocks,
            'attributes' => $content->getPivotedAttributes(),
            'medias' => $content->getMedias(),
        ];

        $stringHelper = $this->container->get('opifer.content.string_helper');
        $json = $this->get('jms_serializer')->serialize($contentItem, 'json', $context);
        $json = $stringHelper->replaceLinks($json);

        $response->setData(json_decode($json, true));

        return $response;
    }