public setLocation ( eZ\Publish\API\Repository\Values\Content\Location $location ) | ||
$location | eZ\Publish\API\Repository\Values\Content\Location |
/** * Tests if $location has match a view that uses a custom controller. * * @since 5.4.5 * * @param $content Content * @param $location Location * @param $viewMode string * * @return bool */ public function usesCustomController(Content $content, Location $location, $viewMode = 'full') { $contentView = new ContentView(null, [], $viewMode); $contentView->setContent($content); $contentView->setLocation($location); foreach ($this->viewProviders as $viewProvider) { $view = $viewProvider->getView($contentView); if ($view instanceof View) { if ($view->getControllerReference() !== null) { return true; } } } return false; }
public function onAPIContentException(APIContentExceptionEvent $event) { $exception = $event->getApiException(); $contentMeta = $event->getContentMeta(); if ($exception instanceof ConverterNotFound) { if (isset($this->logger)) { $this->logger->notice('Missing field converter in legacy storage engine, forwarding to legacy kernel.', array('content' => $contentMeta)); } $contentView = new ContentView(); $contentView->setViewType($contentMeta['viewType']); if (isset($contentMeta['locationId'])) { $contentView->setLocation(new Location(array('id' => $contentMeta['locationId']))); $event->setContentView($this->legacyLVP->getView($contentView)); } elseif (isset($contentMeta['contentId'])) { $contentView->setContent(new Content(array('versionInfo' => new VersionInfo(array('contentInfo' => new ContentInfo(array('id' => $contentMeta['contentId']))))))); $event->setContentView($this->legacyCVP->getView($contentView)); } $event->stopPropagation(); } }
/** * @param array $properties * * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\MVC\Symfony\View\ContentView */ protected function getContentView(array $contentInfoProperties = [], array $locationProperties = []) { $view = new ContentView(); $view->setContent(new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo($contentInfoProperties)])])); $view->setLocation(new Location($locationProperties)); 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'); } $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; }
/** * @param array $properties * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getLocationMock(array $properties = array()) { $view = new ContentView(); $view->setLocation(new Location($properties)); return $view; }
/** * Renders $content by selecting the right template. * $content will be injected in the selected template. * * @param \eZ\Publish\API\Repository\Values\Content\Content $content * @param string $viewType Variation of display for your content. Default is 'full'. * @param array $parameters Parameters to pass to the template called to * render the view. By default, it's empty. 'content' entry is * reserved for the Content that is rendered. * * @throws \RuntimeException * * @return string */ public function renderContent(Content $content, $viewType = ViewManagerInterface::VIEW_TYPE_FULL, $parameters = array()) { $view = new ContentView(null, $parameters, $viewType); $view->setContent($content); if (isset($parameters['location'])) { $view->setLocation($parameters['location']); } $this->viewConfigurator->configure($view); if ($view->getTemplateIdentifier() === null) { throw new RuntimeException('Unable to find a template for #' . $content->contentInfo->id); } return $this->renderContentView($view, $parameters); }