/** * Builds the View based on $parameters. * * @param array $parameters * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If the tag cannot be loaded * * @return \eZ\Publish\Core\MVC\Symfony\View\View An implementation of the View interface */ public function buildView(array $parameters) { $view = new TagView(); if (!empty($parameters['viewType'])) { $view->setViewType($parameters['viewType']); } if (isset($parameters['tagId'])) { $view->setTag($this->tagsService->loadTag($parameters['tagId'])); } elseif (isset($parameters['tag']) && $parameters['tag'] instanceof Tag) { $view->setTag($parameters['tag']); } else { throw new InvalidArgumentException('Tag', 'No tag could be loaded from parameters'); } $this->viewConfigurator->configure($view); // Deprecated controller actions are replaced with their new equivalent, viewAction if (!$view->getControllerReference() instanceof ControllerReference) { if ($parameters['_controller'] === 'eztags.controller.tag_view:viewTag') { $view->setControllerReference(new ControllerReference('eztags.controller.tag_view:viewAction')); } // We want to have a default template for full tag view if ($view->getViewType() === 'full' && $view->getTemplateIdentifier() === null) { $view->setTemplateIdentifier($this->configResolver->getParameter('tag_view.template', 'eztags')); } } $this->viewParametersInjector->injectViewParameters($view, $parameters); return $view; }
public function buildView(array $parameters) { $view = new BlockView(); if (isset($parameters['id'])) { $view->setBlock($this->pageService->loadBlock($parameters['id'])); } elseif ($parameters['block'] instanceof Block) { $view->setBlock($parameters['block']); } $this->viewConfigurator->configure($view); // deprecated controller actions are replaced with their new equivalent, viewAction if (!$view->getControllerReference() instanceof ControllerReference) { if (in_array($parameters['_controller'], ['ez_page:viewBlock', 'ez_page:viewBlockById'])) { $view->setControllerReference(new ControllerReference('ez_page:viewAction')); } } $this->viewParametersInjector->injectViewParameters($view, $parameters); return $view; }
/** * @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'); } } elseif (isset($this->locationLoader)) { try { $location = $this->locationLoader->loadLocation($content->contentInfo); } catch (NotFoundException $e) { // nothing else to do } } if (isset($location)) { $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; }
/** * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException * If both contentId and locationId parameters are missing * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException * * @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 */ 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->contentInfo->id; } else { throw new InvalidArgumentException('Content', 'No content could be loaded from parameters'); } $content = $view->isEmbed() ? $this->loadContent($contentId) : $this->loadEmbeddedContent($contentId, $location); } $view->setSiteContent($content); if (isset($location)) { if ($location->contentInfo->id !== $content->id) { throw new InvalidArgumentException('Location', 'Provided location does not belong to selected content'); } $view->setSiteLocation($location); } $this->viewParametersInjector->injectViewParameters($view, $parameters); $this->viewConfigurator->configure($view); return $view; }