Returns strategy by given webspaceKey.
public getStrategyByWebspaceKey ( string $webspaceKey ) : Sulu\Component\Content\Types\ResourceLocator\Strategy\ResourceLocatorStrategyInterface | ||
$webspaceKey | string | |
리턴 | Sulu\Component\Content\Types\ResourceLocator\Strategy\ResourceLocatorStrategyInterface |
/** * {@inheritdoc} */ public function getParameters() { $result = []; foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) { $result[$webspace->getKey()] = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspace->getKey())->getInputType(); } return $result; }
/** * Returns all urls of the given locale which are associated with the given document. * The returned array contains all current urls and all history urls. * The returned urls can contain placeholders (eg {host}). * * @param ResourceSegmentBehavior $document * @param string $locale * * @return array Urls of the given locale which are associated with the given document */ private function getLocaleUrls(ResourceSegmentBehavior $document, $locale) { $documentUuid = $document instanceof UuidBehavior ? $document->getUuid() : null; $webspace = $document instanceof WebspaceBehavior ? $document->getWebspaceName() : null; if (!$locale || !$documentUuid || !$webspace) { return []; } $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspace); // get current resource-locator and history resource-locators $resourceLocators = []; try { $resourceLocators[] = $resourceLocatorStrategy->loadByContentUuid($documentUuid, $webspace, $locale); } catch (ResourceLocatorNotFoundException $e) { // if no resource locator exists there is also no url to purge from the cache } $historyResourceLocators = $resourceLocatorStrategy->loadHistoryByContentUuid($documentUuid, $webspace, $locale); foreach ($historyResourceLocators as $historyResourceLocator) { $resourceLocators[] = $historyResourceLocator->getResourceLocator(); } // get urls for resource-locators $urls = []; foreach ($resourceLocators as $resourceLocator) { $urls = array_merge($urls, $this->webspaceManager->findUrlsByResourceLocator($resourceLocator, $this->environment, $locale, $webspace)); } return $urls; }
/** * Updates the property for the resource segment on the given node. * * @param NodeInterface $node * @param string $resourceSegmentPropertyName * @param string $parentUuid * @param string $webspaceKey * @param string $locale */ private function updateResourceSegmentProperty(NodeInterface $node, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale) { $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); $childPart = $resourceLocatorStrategy->getChildPart($node->getPropertyValue($resourceSegmentPropertyName)); $node->setProperty($resourceSegmentPropertyName, $resourceLocatorStrategy->generate($childPart, $parentUuid, $webspaceKey, $locale)); }
/** * Finds the correct route for the current request. * It loads the correct data with the content mapper. * * @param Request $request A request against which to match * * @return \Symfony\Component\Routing\RouteCollection with all Routes that * could potentially match $request. Empty collection if nothing can * match */ public function getRouteCollectionForRequest(Request $request) { $collection = new RouteCollection(); // no portal information without localization supported if ($this->requestAnalyzer->getCurrentLocalization() === null && $this->requestAnalyzer->getMatchType() !== RequestAnalyzerInterface::MATCH_TYPE_PARTIAL && $this->requestAnalyzer->getMatchType() !== RequestAnalyzerInterface::MATCH_TYPE_REDIRECT) { return $collection; } $htmlExtension = '.html'; $resourceLocator = $this->requestAnalyzer->getResourceLocator(); if ($this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_REDIRECT || $this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_PARTIAL) { // redirect webspace correctly with locale $collection->add('redirect_' . uniqid(), $this->getRedirectWebSpaceRoute()); } elseif ($request->getRequestFormat() === 'html' && substr($request->getPathInfo(), -strlen($htmlExtension)) === $htmlExtension) { // redirect *.html to * (without url) $collection->add('redirect_' . uniqid(), $this->getRedirectRoute($request, $this->getUrlWithoutEndingTrailingSlash($resourceLocator))); } else { // just show the page $portal = $this->requestAnalyzer->getPortal(); $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization(); $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($portal->getWebspace()->getKey()); try { // load content by url ignore ending trailing slash /** @var PageDocument $document */ $document = $this->documentManager->find($resourceLocatorStrategy->loadByResourceLocator(rtrim($resourceLocator, '/'), $portal->getWebspace()->getKey(), $locale), $locale, ['load_ghost_content' => false]); if (!$document->getTitle()) { // If the title is empty the document does not exist in this locale // Necessary because of https://github.com/sulu/sulu/issues/2724, otherwise locale could be checked return $collection; } if (preg_match('/\\/$/', $resourceLocator) && $this->requestAnalyzer->getResourceLocatorPrefix()) { // redirect page to page without slash at the end $collection->add('redirect_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . rtrim($resourceLocator, '/'))); } elseif ($document->getRedirectType() === RedirectType::INTERNAL) { // redirect internal link $redirectUrl = $this->requestAnalyzer->getResourceLocatorPrefix() . $document->getRedirectTarget()->getResourceSegment(); if ($request->getQueryString()) { $redirectUrl .= '?' . $request->getQueryString(); } $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getRedirectRoute($request, $redirectUrl)); } elseif ($document->getRedirectType() === RedirectType::EXTERNAL) { $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getRedirectRoute($request, $document->getRedirectExternal())); } elseif (!$this->checkResourceLocator()) { return $collection; } else { // convert the page to a StructureBridge because of BC /** @var PageBridge $structure */ $structure = $this->structureManager->wrapStructure($this->documentInspector->getMetadata($document)->getAlias(), $this->documentInspector->getStructureMetadata($document)); $structure->setDocument($document); // show the page $collection->add($document->getStructureType() . '_' . $document->getUuid(), $this->getStructureRoute($request, $structure)); } } catch (ResourceLocatorNotFoundException $exc) { // just do not add any routes to the collection } catch (ResourceLocatorMovedException $exc) { // old url resource was moved $collection->add($exc->getNewResourceLocatorUuid() . '_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . $exc->getNewResourceLocator())); } catch (RepositoryException $exc) { // just do not add any routes to the collection } } return $collection; }
/** * {@inheritdoc} */ public function delete($path, $webspaceKey, $languageCode, $segmentKey = null) { $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); $resourceLocatorStrategy->deleteByPath($path, $webspaceKey, $languageCode, $segmentKey); }
/** * {@inheritdoc} */ public function copyLanguage($uuid, $userId, $webspaceKey, $srcLocale, $destLocales, $structureType = LegacyStructure::TYPE_PAGE) { if (!is_array($destLocales)) { $destLocales = [$destLocales]; } $document = $this->documentManager->find($uuid, $srcLocale); $parentDocument = $this->inspector->getParent($document); if ($document instanceof ResourceSegmentBehavior) { $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); } foreach ($destLocales as $destLocale) { $destDocument = $this->documentManager->find($uuid, $destLocale); $destDocument->setLocale($destLocale); $destDocument->getStructure()->bind($document->getStructure()->toArray()); // TODO: This can be removed if RoutingAuto replaces the ResourceLocator code. if ($destDocument instanceof ResourceSegmentBehavior) { $resourceLocator = $resourceLocatorStrategy->generate($destDocument->getTitle(), $this->inspector->getUuid($parentDocument), $webspaceKey, $destLocale); $destDocument->setResourceSegment($resourceLocator); } $this->documentManager->persist($destDocument, $destLocale); } $this->documentManager->flush(); return $this->documentToStructure($document); }