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

embedLocation() public method

Response will be cached with HttpCache validation model (Etag).
Deprecation: Since 6.0.0. Viewing locations is now done with ViewContent.
public embedLocation ( integer $locationId, string $viewType, boolean $layout = false, array $params = [] ) : Response
$locationId integer
$viewType string
$layout boolean
$params array
return Symfony\Component\HttpFoundation\Response
    public function embedLocation($locationId, $viewType, $layout = false, array $params = array())
    {
        trigger_error("ViewController::embedLocation() 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\Location $location */
            $location = $this->getRepository()->sudo(function (Repository $repository) use($locationId) {
                return $repository->getLocationService()->loadLocation($locationId);
            });
            if ($location->invisible) {
                throw new NotFoundHttpException("Location #{$locationId} cannot be displayed as it is flagged as invisible.");
            }
            // Check both 'content/read' and 'content/view_embed'.
            if (!$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'read', array('valueObject' => $location->contentInfo, 'targets' => $location))) && !$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'view_embed', array('valueObject' => $location->contentInfo, 'targets' => $location)))) {
                throw new AccessDeniedException();
            }
            if ($response->isNotModified($this->getRequest())) {
                return $response;
            }
            $response->headers->set('X-Location-Id', $locationId);
            $response->setContent($this->renderLocation($location, $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, null, $locationId);
        }
    }