/** * Returns content name, translated, from a ContentInfo object. * By default this method uses prioritized languages, unless $forcedLanguage is provided. * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) * * @todo Remove ContentService usage when translated names are available in ContentInfo (see https://jira.ez.no/browse/EZP-21755) * * @return string */ public function getTranslatedContentNameByContentInfo(ContentInfo $contentInfo, $forcedLanguage = null) { if (isset($forcedLanguage) && $forcedLanguage === $contentInfo->mainLanguageCode) { return $contentInfo->name; } return $this->getTranslatedContentName($this->contentService->loadContentByContentInfo($contentInfo), $forcedLanguage); }
/** * 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; }
/** * @Given /^there is a User Content$/ */ public function thereIsAUserContent() { $login = '******' . microtime(true); $email = $login . '@example.com'; $struct = $this->userService->newUserCreateStruct($login, $email, 'publish', 'eng-GB'); $struct->setField('first_name', 'John'); $struct->setField('last_name', 'Doe'); $parentGroup = $this->userService->loadUserGroup(11); $user = $this->userService->createUser($struct, [$parentGroup]); $this->currentContent = $this->contentService->loadContentByContentInfo($user->contentInfo); }
/** * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @return \Heliopsis\eZFormsBundle\FormHandler\FormHandlerInterface */ private function getHandler(Location $location) { $handler = $this->formFacade->getHandler($location); if ($handler instanceof LocationAwareHandlerInterface) { $handler->setLocation($location); } if ($handler instanceof ContentAwareHandlerInterface) { $handler->setContent($this->contentService->loadContentByContentInfo($location->contentInfo)); } return $handler; }
/** * 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; }
/** * Loads content in a version for the given content info object. * * If no version number is given, the method returns the current version * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param array $languages A language filter for fields. If not given all languages are returned * @param int $versionNo the version number. If not given the current version is returned. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null) { return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo); }
/** * Returns footer content object. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function getFooter() { $location = $this->locationService->loadLocation($this->locationSettings['footer']); return $this->contentService->loadContentByContentInfo($location->getContentInfo()); }
/** * Loads content in a version for the given content info object. * * If no version number is given, the method returns the current version * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param array $languages A language filter for fields. If not given all languages are returned * @param int $versionNo the version number. If not given the current version is returned * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) { return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo, $useAlwaysAvailable); }
/** * 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; }
/** * @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); }