/** * @param array $parameters * * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView|\eZ\Publish\Core\MVC\Symfony\View\View * If both contentId and locationId parameters are missing * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException * If both contentId and locationId parameters are missing * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException */ public function buildView(array $parameters) { $view = new ContentView(null, [], $parameters['viewType']); $view->setIsEmbed($this->isEmbed($parameters)); if ($view->isEmbed() && $parameters['viewType'] === null) { $view->setViewType(EmbedView::DEFAULT_VIEW_TYPE); } if (isset($parameters['locationId'])) { $location = $this->loadLocation($parameters['locationId']); } elseif (isset($parameters['location'])) { $location = $parameters['location']; } else { $location = null; } if (isset($parameters['content'])) { $content = $parameters['content']; } else { if (isset($parameters['contentId'])) { $contentId = $parameters['contentId']; } elseif (isset($location)) { $contentId = $location->contentId; } else { throw new InvalidArgumentException('Content', 'No content could be loaded from parameters'); } $content = $view->isEmbed() ? $this->loadContent($contentId) : $this->loadEmbeddedContent($contentId, $location); } $view->setContent($content); if (isset($location)) { if ($location->contentId !== $content->id) { throw new InvalidArgumentException('Location', 'Provided location does not belong to selected content'); } $view->setLocation($location); } $this->viewParametersInjector->injectViewParameters($view, $parameters); $this->viewConfigurator->configure($view); // deprecated controller actions are replaced with their new equivalent, viewAction and embedAction if (!$view->getControllerReference() instanceof ControllerReference) { if (in_array($parameters['_controller'], ['ez_content:viewLocation', 'ez_content:viewContent'])) { $view->setControllerReference(new ControllerReference('ez_content:viewAction')); } elseif (in_array($parameters['_controller'], ['ez_content:embedLocation', 'ez_content:embedContent'])) { $view->setControllerReference(new ControllerReference('ez_content:embedAction')); } } return $view; }