Returns the webspace with the given key.
public findWebspaceByKey ( $key ) : |
||
$key | string The key to search for | |
return |
public function findAvailableLocale($webspaceName, array $availableLocales, $locale) { if (!$webspaceName) { return; } // get localization object for querying parent localizations $webspace = $this->webspaceManager->findWebspaceByKey($webspaceName); $localization = $webspace->getLocalization($locale); if (null === $localization) { return; } $resultLocalization = null; // find first available localization in parents $resultLocalization = $this->findAvailableParentLocalization($availableLocales, $localization); // find first available localization in children, if no result is found yet if (!$resultLocalization) { $resultLocalization = $this->findAvailableChildLocalization($availableLocales, $localization); } // find any localization available, if no result is found yet if (!$resultLocalization) { $resultLocalization = $this->findAvailableLocalization($availableLocales, $webspace->getLocalizations()); } if (!$resultLocalization) { return; } return $resultLocalization->getLocale(); }
protected function prepareWebspaceManager() { if ($this->webspaceManager === null) { $webspace = new Webspace(); $en = new Localization(); $en->setLanguage('en'); $en_us = new Localization(); $en_us->setLanguage('en'); $en_us->setCountry('us'); $en_us->setParent($en); $en->addChild($en_us); $de = new Localization(); $de->setLanguage('de'); $de_at = new Localization(); $de_at->setLanguage('de'); $de_at->setCountry('at'); $de_at->setParent($de); $de->addChild($de_at); $es = new Localization(); $es->setLanguage('es'); $webspace->addLocalization($en); $webspace->addLocalization($de); $webspace->addLocalization($es); $this->webspaceManager = $this->prophesize('Sulu\\Component\\Webspace\\Manager\\WebspaceManagerInterface'); $this->webspaceManager->findWebspaceByKey('sulu_io')->willReturn($webspace); } }
/** * @param $webspaceKey * * @return WebspaceSitemap */ private function getWebspaceSitemap($webspaceKey) { $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); $webspaceSitemap = new WebspaceSitemap(); $webspaceSitemap->setWebspaceKey($webspace->getKey()); $defaultLocalization = $webspace->getDefaultLocalization(); if ($defaultLocalization) { $webspaceSitemap->setDefaultLocalization($defaultLocalization->getLocalization()); } foreach ($webspace->getAllLocalizations() as $localization) { $webspaceSitemap->addLocalization($localization->getLocalization()); } return $webspaceSitemap; }
/** * {@inheritdoc} */ public function process(Request $request, RequestAttributes $requestAttributes) { $attributes = []; $attributes['webspaceKey'] = $request->get('webspace'); $attributes['locale'] = $request->get('locale', $request->get('language')); if (empty($attributes['webspaceKey'])) { return new RequestAttributes($attributes); } $attributes['webspace'] = $this->webspaceManager->findWebspaceByKey($attributes['webspaceKey']); if (null === $attributes['locale']) { return new RequestAttributes($attributes); } $attributes['localization'] = $attributes['webspace']->getLocalization($attributes['locale']); return new RequestAttributes($attributes); }
/** * Returns array of locales for given webspace key. * * @param string $webspaceKey * * @return string[] */ private function getLocalesByWebspaceKey($webspaceKey) { $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); return array_map(function (Localization $localization) { return $localization->getLocalization(); }, $webspace->getAllLocalizations()); }
/** * {@inheritdoc} */ public function getFilteredNodes(array $filterConfig, $languageCode, $webspaceKey, $preview = false, $api = false, $exclude = []) { $limit = isset($filterConfig['limitResult']) ? $filterConfig['limitResult'] : null; $initParams = ['config' => $filterConfig]; if ($exclude) { $initParams['excluded'] = $exclude; } $this->queryBuilder->init($initParams); $data = $this->queryExecutor->execute($webspaceKey, [$languageCode], $this->queryBuilder, true, -1, $limit); if ($api) { if (isset($filterConfig['dataSource'])) { if ($this->webspaceManager->findWebspaceByKey($filterConfig['dataSource']) !== null) { $node = $this->sessionManager->getContentNode($filterConfig['dataSource']); } else { $node = $this->sessionManager->getSession()->getNodeByIdentifier($filterConfig['dataSource']); } } else { $node = $this->sessionManager->getContentNode($webspaceKey); } $parentNode = $this->getParentNode($node->getIdentifier(), $webspaceKey, $languageCode); $result = $this->prepareNode($parentNode, $webspaceKey, $languageCode, 1, false); $result['_embedded']['nodes'] = $data; $result['total'] = count($result['_embedded']['nodes']); } else { $result = $data; } return $result; }
public function setUp() { parent::setUp(); $this->webspaceManager = $this->prophesize(WebspaceManagerInterface::class); $this->inspector = $this->prophesize(DocumentInspector::class); $this->registry = $this->prophesize(DocumentRegistry::class); $this->document = $this->prophesize(StructureBehavior::class)->willImplement(WebspaceBehavior::class); $this->webspace = $this->prophesize(Webspace::class); $this->localization1 = $this->prophesize(Localization::class); $this->localization2 = $this->prophesize(Localization::class); $this->subscriber = new FallbackLocalizationSubscriber($this->encoder->reveal(), $this->inspector->reveal(), $this->registry->reveal(), new LocalizationFinder($this->webspaceManager->reveal())); $this->hydrateEvent->getNode()->willReturn($this->node->reveal()); $this->hydrateEvent->getDocument()->willReturn($this->document->reveal()); $this->hydrateEvent->getLocale()->willReturn(self::FIX_LOCALE); $this->webspaceManager->findWebspaceByKey(self::FIX_WEBSPACE)->willReturn($this->webspace); $this->registry->getDefaultLocale()->willReturn('de'); }
/** * Return the default structure for the given StructureBehavior implementing document. * * @param StructureBehavior $document * * @return string */ private function getDefaultStructureType(StructureBehavior $document) { $alias = $this->inspector->getMetadata($document)->getAlias(); $webspace = $this->webspaceManager->findWebspaceByKey($this->inspector->getWebspace($document)); if (!$webspace) { return $this->getDefaultStructureTypeFromConfig($alias); } return $webspace->getDefaultTemplate($alias); }
private function loadStructures($webspaceKey) { $before = $this->activeTheme->getName(); $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); $this->activeTheme->setName($webspace->getTheme()->getKey()); $structures = []; $keys = []; foreach ($this->structureManager->getStructures() as $page) { /* @var PageBridge $page */ $template = sprintf('%s.html.twig', $page->getView()); if ($this->templateExists($template)) { $keys[] = $page->getKey(); $structures[] = $page; } } $this->activeTheme->setName($before); $this->cache->save($webspaceKey, $keys); return $structures; }
/** * renders content with the real website controller. * * @param PageBridge $content * @param bool $partial * * @return string */ public function render(PageBridge $content, $partial = false) { // set active theme $webspace = $this->webspaceManager->findWebspaceByKey($content->getWebspaceKey()); $this->activeTheme->setName($webspace->getTheme()->getKey()); // get controller and invoke action $request = new Request(); $request->attributes->set('_controller', $content->getController()); $controller = $this->controllerResolver->getController($request); // prepare locale for translator and request $request->setLocale($content->getLanguageCode()); $localeBefore = $this->translator->getLocale(); $this->translator->setLocale($content->getLanguageCode()); $this->requestStack->push($request); /** @var Response $response */ $response = $controller[0]->{$controller[1]}($content, true, $partial); // roll back $this->requestStack->pop(); $this->translator->setLocale($localeBefore); return $response->getContent(); }
/** * build datasource where clause. */ private function buildDatasourceWhere() { $dataSource = $this->getConfig('dataSource'); $includeSubFolders = $this->getConfig('includeSubFolders', false); $sqlFunction = $includeSubFolders !== false && $includeSubFolders !== 'false' ? 'ISDESCENDANTNODE' : 'ISCHILDNODE'; if ($this->webspaceManager->findWebspaceByKey($dataSource) !== null) { $node = $this->sessionManager->getContentNode($dataSource); } else { $node = $this->sessionManager->getSession()->getNodeByIdentifier($dataSource); } return $sqlFunction . '(page, \'' . $node->getPath() . '\')'; }
/** * {@inheritdoc} */ public function getContentPath($route, $webspaceKey = null, $locale = null, $domain = null, $scheme = null, $withoutDomain = true) { // if the request analyzer null or a route is passed which is relative or inclusive a domain nothing should be // done (this is important for external-links in navigations) if (!$this->requestAnalyzer || strpos($route, '/') !== 0) { return $route; } $scheme = $scheme ?: $this->requestAnalyzer->getAttribute('scheme'); $locale = $locale ?: $this->requestAnalyzer->getCurrentLocalization()->getLocale(); $webspaceKey = $webspaceKey ?: $this->requestAnalyzer->getWebspace()->getKey(); $url = null; $host = $this->requestAnalyzer->getAttribute('host'); if (!$domain && $this->webspaceManager->findWebspaceByKey($webspaceKey)->hasDomain($host, $this->environment)) { $domain = $host; } $url = $this->webspaceManager->findUrlByResourceLocator($route, $this->environment, $locale, $webspaceKey, $domain, $scheme); if (!$withoutDomain && !$url) { $url = $this->webspaceManager->findUrlByResourceLocator($route, $this->environment, $locale, $webspaceKey, null, $scheme); } return $url ?: $route; }
/** * Copy or move a node by UUID to a detination parent. * * Note that the bulk of this method is about the resource locator and can * be removed if we integrate the RoutingAuto component. * * @param string $webspaceKey * @param string $locale * @param bool $move * * @return StructureInterface */ private function copyOrMove($uuid, $destParentUuid, $userId, $webspaceKey, $locale, $move = true) { // find localizations $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); $localizations = $webspace->getAllLocalizations(); // load from phpcr $document = $this->documentManager->find($uuid, $locale); $parentDocument = $this->documentManager->find($destParentUuid, $locale); if ($move) { // move node $this->documentManager->move($document, $destParentUuid); } else { // copy node $copiedPath = $this->documentManager->copy($document, $destParentUuid); $document = $this->documentManager->find($copiedPath, $locale); $this->documentManager->refresh($parentDocument); } $originalLocale = $locale; // modifiy the resource locators -- note this can be removed once the routing auto // system is implemented. foreach ($localizations as $locale) { $locale = $locale->getLocalization(); if (!$document instanceof ResourceSegmentBehavior) { break; } // prepare parent content node // finding the document will update the locale without reloading from PHPCR $this->documentManager->find($document->getUuid(), $locale); $this->documentManager->find($parentDocument->getUuid(), $locale); $parentResourceLocator = '/'; if ($parentDocument instanceof ResourceSegmentBehavior) { $parentResourceLocator = $parentDocument->getResourceSegment(); } // TODO: This could be optimized $localizationState = $this->inspector->getLocalizationState($document); if ($localizationState !== LocalizationState::LOCALIZED) { continue; } if ($document->getRedirectType() !== RedirectType::NONE) { continue; } $strategy = $this->getResourceLocator()->getStrategy(); $nodeName = PathHelper::getNodeName($document->getResourceSegment()); $newResourceLocator = $strategy->generate($nodeName, $parentDocument->getResourceSegment(), $webspaceKey, $locale); $document->setResourceSegment($newResourceLocator); $this->documentManager->persist($document, $locale, array('user' => $userId)); } $this->documentManager->flush(); // $this->documentManager->find($document->getUuid(), $originalLocale); return $this->documentToStructure($document); }
/** * Creates routes for persisted custom-url. * * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof CustomUrlBehavior) { return; } $oldRoutes = $document->getRoutes(); $webspaceKey = $this->inspector->getWebspace($document); $domain = $this->generator->generate($document->getBaseDomain(), $document->getDomainParts()); $locale = $this->webspaceManager->findWebspaceByKey($webspaceKey)->getLocalization($document->getTargetLocale()); $route = $this->createRoute($domain, $document, $locale, $event->getLocale(), $this->getRoutesPath($webspaceKey)); if (!array_key_exists($domain, $oldRoutes)) { $document->addRoute($domain, $route); } foreach ($oldRoutes as $oldRoute) { if ($oldRoute->getPath() === $route->getPath()) { continue; } $oldRoute->setTargetDocument($route); $oldRoute->setHistory(true); $this->documentManager->persist($oldRoute, $event->getLocale(), ['path' => $oldRoute->getPath(), 'auto_create' => true]); $this->documentManager->publish($oldRoute, $locale); } }
/** * {@inheritdoc} */ public function getStrategyByWebspaceKey($webspaceKey) { $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); return $this->getStrategy($webspace->getResourceLocatorStrategy()); }
/** * set webspace for current request. * * @param string $webspaceKey */ public function setWebspaceKey($webspaceKey) { $this->webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); }