Example #1
0
 /**
  * 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)
 {
     $collector = $this->getCollector($parameters['systemInfoIdentifier']);
     $view = new SystemInfoView(null, [], $parameters['viewType']);
     $view->setInfo($collector->collect());
     $this->viewConfigurator->configure($view);
     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;
 }
Example #4
0
 /**
  * Renders $block by selecting the right template.
  * $block will be injected in the selected template.
  *
  * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block
  * @param array $parameters Parameters to pass to the template called to
  *        render the view. By default, it's empty.
  *        'block' entry is reserved for the Block that is viewed.
  *
  * @throws \RuntimeException
  *
  * @return string
  */
 public function renderBlock(Block $block, $parameters = array())
 {
     $view = new BlockView(null, $parameters);
     $view->setBlock($block);
     $this->viewConfigurator->configure($view);
     if ($view->getTemplateIdentifier() === null) {
         throw new RuntimeException("Unable to find a view for location #{$block->id}");
     }
     return $this->renderContentView($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;
 }
 public function testRenderLocationWithClosure()
 {
     $content = new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo()])]);
     $location = new Location(['contentInfo' => new ContentInfo()]);
     // Configuring view provider behaviour
     $closure = function ($params) {
         return serialize(array_keys($params));
     };
     $params = array('foo' => 'bar');
     $this->viewConfigurator->expects($this->once())->method('configure')->will($this->returnCallback(function (View $view) use($closure) {
         $view->setTemplateIdentifier($closure);
     }));
     $contentService = $this->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')->disableOriginalConstructor()->getMock();
     $contentService->expects($this->any())->method('loadContentByContentInfo')->with($content->contentInfo)->will($this->returnValue($content));
     $this->repositoryMock->expects($this->any())->method('getContentService')->will($this->returnValue($contentService));
     // Configuring template engine behaviour
     $params += array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout);
     $this->templateEngineMock->expects($this->never())->method('render');
     $expectedTemplateResult = array_keys($params);
     $templateResult = unserialize($this->viewManager->renderLocation($location, 'full', $params));
     sort($expectedTemplateResult);
     sort($templateResult);
     self::assertSame($expectedTemplateResult, $templateResult);
 }