eZ\Publish\Core\MVC\Symfony\Controller\Content\ViewController::embedContent PHP Method

embedContent() public method

Response will be cached with HttpCache validation model (Etag).
public embedContent ( integer $contentId, string $viewType, boolean $layout = false, array $params = [] ) : Response
$contentId integer
$viewType string
$layout boolean
$params array
return Symfony\Component\HttpFoundation\Response
    public function embedContent($contentId, $viewType, $layout = false, array $params = array())
    {
        trigger_error("ViewController::embedContent() is deprecated since kernel 6.0.0, and will be removed in the future.\n" . 'Use ViewController::viewAction() instead.', E_USER_DEPRECATED);
        $this->performAccessChecks();
        $response = $this->buildResponse();
        try {
            /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
            $content = $this->getRepository()->sudo(function (Repository $repository) use($contentId) {
                return $repository->getContentService()->loadContent($contentId);
            });
            // Check both 'content/read' and 'content/view_embed'.
            if (!$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'read', array('valueObject' => $content))) && !$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'view_embed', array('valueObject' => $content)))) {
                throw new AccessDeniedException();
            }
            // Check that Content is published, since sudo allows loading unpublished content.
            if ($content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED && !$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'versionread', array('valueObject' => $content)))) {
                throw new AccessDeniedException();
            }
            if ($response->isNotModified($this->getRequest())) {
                return $response;
            }
            $response->setContent($this->renderContent($content, $viewType, $layout, $params));
            return $response;
        } catch (UnauthorizedException $e) {
            throw new AccessDeniedException();
        } catch (NotFoundException $e) {
            throw new NotFoundHttpException($e->getMessage(), $e);
        } catch (Exception $e) {
            return $this->handleViewException($response, $params, $e, $viewType, $contentId);
        }
    }