Holds the path to the template to be rendered by the view manager and the parameters to inject in it. The template path can be a closure. In that case, the view manager will invoke it instead of loading a template. $parameters will be passed to the callable in addition to the Content or Location object (depending on the context). The prototype of the closure must be : namespace Foo; use eZ\Publish\API\Repository\Values\Content\ContentInfo; use eZ\Publish\API\Repository\Values\Content\Location; For a content function ( ContentInfo $contentInfo, array $parameters = array() ) { Do something to render Must return a string to display } For a location function ( Location $location, array $parameters = array() ) { Do something to render Must return a string to display }
Inheritance: extends eZ\Publish\Core\MVC\Symfony\View\BaseView, implements eZ\Publish\Core\MVC\Symfony\View\View, implements eZ\Publish\Core\MVC\Symfony\View\ContentValueView, implements eZ\Publish\Core\MVC\Symfony\View\LocationValueView, implements eZ\Publish\Core\MVC\Symfony\View\EmbedView, implements eZ\Publish\Core\MVC\Symfony\View\CachableView
コード例 #1
0
 /**
  * Displays the list of article.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request request object
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  *
  * @return \Symfony\Component\HttpFoundation\Response $location is flagged as invisible
  */
 public function showFolderListAction(Request $request, ContentView $view)
 {
     $languages = $this->getConfigResolver()->getParameter('languages');
     // Using the criteria helper (a demobundle custom service) to generate our query's criteria.
     // This is a good practice in order to have less code in your controller.
     $criteria = $this->get('ezdemo.criteria_helper')->generateListFolderCriterion($view->getLocation(), $this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types'), $languages);
     // Generating query
     $query = new LocationQuery();
     $query->query = $criteria;
     $query->sortClauses = array(new SortClause\DatePublished());
     // Initialize pagination.
     $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService()));
     $pager->setMaxPerPage($this->container->getParameter('ezdemo.folder.folder_list.limit'));
     $pager->setCurrentPage($request->get('page', 1));
     $includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types');
     // Get sub folder structure
     $subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion($view->getLocation(), $includedContentTypeIdentifiers, $languages);
     $subContentQuery = new LocationQuery();
     $subContentQuery->query = $subContentCriteria;
     $subContentQuery->sortClauses = array(new SortClause\ContentName());
     $searchService = $this->getRepository()->getSearchService();
     $subContent = $searchService->findLocations($subContentQuery);
     $treeItems = array();
     foreach ($subContent->searchHits as $hit) {
         $treeItems[] = $hit->valueObject;
     }
     $view->addParameters(['pagerFolder' => $pager, 'treeItems' => $treeItems]);
     return $view;
 }
コード例 #2
0
 /**
  * Builds a ContentView object from $viewConfig.
  *
  * @param array $viewConfig
  *
  * @throws \InvalidArgumentException
  *
  * @return ContentView
  */
 protected function buildContentView(array $viewConfig)
 {
     if (!isset($viewConfig['template'])) {
         throw new InvalidArgumentException('$viewConfig must contain the template identifier in order to correctly generate the ContentView object');
     }
     $view = new ContentView($viewConfig['template']);
     $view->setConfigHash($viewConfig);
     return $view;
 }
 /**
  * @param ContentView $contentView
  * @param string $queryParameterValue
  *
  * @return mixed
  */
 private function evaluateExpression(ContentView $contentView, $queryParameterValue)
 {
     if (substr($queryParameterValue, 0, 2) === '@=') {
         $language = new ExpressionLanguage();
         return $language->evaluate(substr($queryParameterValue, 2), ['view' => $contentView, 'location' => $contentView->getLocation(), 'content' => $contentView->getContent()]);
     } else {
         return $queryParameterValue;
     }
 }
コード例 #4
0
 public function listRidesAction(ContentView $view)
 {
     $searchService = $this->get('ezpublish.api.service.search');
     $query = new LocationQuery();
     $query->filter = new Criterion\LogicalAnd([new Criterion\Visibility(Criterion\Visibility::VISIBLE), new Criterion\ContentTypeIdentifier('ride')]);
     $query->sortClauses = [new SortClause\DatePublished()];
     $result = $searchService->findLocations($query);
     $view->addParameters(['rides_list' => $result->searchHits]);
     return $view;
 }
コード例 #5
0
 /**
  * @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;
 }
コード例 #6
0
 /**
  * Displays the gallery.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function displayGalleryAction(ContentView $view, Request $request)
 {
     $languages = $this->configResolver->getParameter('languages');
     $location = $view->getLocation();
     $query = new Query();
     $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
     $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->searchService));
     $pager->setMaxPerPage($this->galleryImagesLimit);
     $pager->setCurrentPage($request->get('page', 1));
     $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'images' => $pager]);
     return $view;
 }
コード例 #7
0
ファイル: Configured.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Builds a ContentView object from $viewConfig.
  *
  * @param array $viewConfig
  *
  * @return ContentView
  */
 protected function buildContentView(array $viewConfig)
 {
     $view = new ContentView();
     $view->setConfigHash($viewConfig);
     if (isset($viewConfig['template'])) {
         $view->setTemplateIdentifier($viewConfig['template']);
     }
     if (isset($viewConfig['controller'])) {
         $view->setControllerReference(new ControllerReference($viewConfig['controller']));
     }
     return $view;
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
 /**
  * Displays blog post content with random selected blog posts.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  *
  * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView
  */
 public function showBlogPostAction(ContentView $view)
 {
     $languages = $this->configResolver->getParameter('languages');
     $location = $this->locationService->loadLocation($view->getLocation()->parentLocationId);
     $query = new Query();
     $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
     $query->performCount = false;
     $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
     $results = $this->searchService->findContent($query);
     $randomPosts = [];
     foreach ($results->searchHits as $item) {
         $randomPosts[] = $item->valueObject;
     }
     shuffle($randomPosts);
     $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'randomPosts' => array_slice($randomPosts, 0, $this->randomPostsLimit, true)]);
     return $view;
 }
コード例 #10
0
 /**
  * Displays the feedback form, and processes posted data.
  * The signature of this method follows the one from the default view controller, and adds the Request, since
  * we use to handle form data.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  *
  * @return View
  */
 public function showFeedbackFormAction(Request $request, ContentView $view)
 {
     // Creating a form using Symfony's form component
     $feedback = new Feedback();
     $form = $this->createForm($this->get('ezdemo.form.type.feedback'), $feedback);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             /** @var EmailHelper $emailHelper */
             $emailHelper = $this->get('ezdemo.email_helper');
             $emailHelper->sendFeebackMessage($feedback, $this->container->getParameter('ezdemo.feedback_form.email_from'), $this->container->getParameter('ezdemo.feedback_form.email_to'));
             // Adding the confirmation flash message to the session
             $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('Thank you for your message, we will get back to you as soon as possible.'));
             return $this->redirect($this->generateUrl($view->getLocation()));
         }
     }
     $view->addParameters(['form' => $form->createView()]);
     return $view;
 }
コード例 #11
0
 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();
     }
 }
コード例 #12
0
 /**
  * @param array $properties
  *
  * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\MVC\Symfony\View\ContentView
  */
 protected function getContentInfoMock(array $properties = array())
 {
     $view = new ContentView();
     $view->setContent(new Content($properties));
     return $view;
 }
コード例 #13
0
 /**
  * Action used to display a blog_post
  *  - Adds the content's author to the response.
  * Note: This is a partly customized controller action. It is executed just before the original
  *       Viewcontroller's viewLocation method. To be able to do that, we need to implement it's
  *       full signature.
  *
  * @param ContentView $view
  *
  * @return View
  */
 public function showBlogPostAction(ContentView $view)
 {
     $author = $this->getRepository()->getUserService()->loadUser($view->getContent()->contentInfo->ownerId);
     $view->addParameters(['author' => $author]);
     return $view;
 }
コード例 #14
0
 /**
  * Returns parameter value by $parameterName.
  * Throws an \InvalidArgumentException if $parameterName is not set.
  *
  * @param string $parameterName
  *
  * @throws \InvalidArgumentException
  *
  * @return mixed
  */
 public function getParameter($parameterName)
 {
     return $this->contentView->getParameter($parameterName);
 }
コード例 #15
0
 /**
  * @dataProvider badTemplateIdentifierProvider
  *
  * @expectedException eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
  *
  * @param $badTemplateIdentifier
  */
 public function testSetTemplateIdentifierWrongType($badTemplateIdentifier)
 {
     $contentView = new ContentView();
     $contentView->setTemplateIdentifier($badTemplateIdentifier);
 }
コード例 #16
0
 /**
  * Displays blog posts and gallery images on home page.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
  *
  * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView
  */
 public function showAction(ContentView $view)
 {
     $view->addParameters(['content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'blogPosts' => $this->fetchItems($this->blogLocationId, $this->blogPostLimit), 'galleryImages' => $this->fetchItems($this->galleryLocationId, $this->galleryImageLimit), 'galleryLocationId' => $this->galleryLocationId]);
     return $view;
 }
コード例 #17
0
 public function testGetControllerMatchedView()
 {
     $id = 123;
     $viewType = 'full';
     $templateIdentifier = 'FooBundle:full:template.twig.html';
     $customController = 'FooBundle::bar';
     $this->request->attributes->add(array('_controller' => 'ez_content:viewLocation', 'locationId' => $id, 'viewType' => $viewType));
     $this->viewBuilderRegistry->expects($this->once())->method('getFromRegistry')->will($this->returnValue($this->viewBuilderMock));
     $viewObject = new ContentView($templateIdentifier);
     $viewObject->setControllerReference(new ControllerReference($customController));
     $this->viewBuilderMock->expects($this->once())->method('buildView')->will($this->returnValue($viewObject));
     $this->event->expects($this->once())->method('setController');
     $this->controllerResolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
     }));
     $this->controllerListener->getController($this->event);
     $this->assertEquals($customController, $this->request->attributes->get('_controller'));
     $expectedView = new ContentView();
     $expectedView->setTemplateIdentifier($templateIdentifier);
     $expectedView->setControllerReference(new ControllerReference($customController));
     $this->assertEquals($expectedView, $this->request->attributes->get('view'));
 }
コード例 #18
0
ファイル: Manager.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * 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);
 }
コード例 #19
0
 /**
  * @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;
 }
コード例 #20
0
 /**
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  *
  * @note Matched config is cached in memory by underlying matcher factory.
  *
  * @return array|null
  */
 private function getCommentsConfig(ContentInfo $contentInfo)
 {
     $view = new ContentView(null, [], 'comments');
     $view->setContent($this->contentService->loadContentByContentInfo($contentInfo));
     return $this->matcherFactory->match($view);
 }