getKey() public method

Returns the key of the webspace.
public getKey ( ) : string
return string
Example #1
0
 private function initializeWebspace(OutputInterface $output, Webspace $webspace)
 {
     $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']);
     $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']);
     $webspaceLocales = [];
     foreach ($webspace->getAllLocalizations() as $localization) {
         $webspaceLocales[] = $localization->getLocalization();
     }
     if ($this->nodeManager->has($homePath)) {
         $homeDocument = $this->documentManager->find($homePath, 'fr', ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]);
         $existingLocales = $this->inspector->getLocales($homeDocument);
     } else {
         $homeDocument = new HomeDocument();
         $homeDocument->setTitle('Homepage');
         $homeDocument->setStructureType($webspace->getTheme()->getDefaultTemplate('homepage'));
         $homeDocument->setWorkflowStage(WorkflowStage::PUBLISHED);
         $existingLocales = [];
     }
     foreach ($webspaceLocales as $webspaceLocale) {
         $output->writeln(sprintf('<info>Homepage</info>: %s (%s)', $homePath, $webspaceLocale));
         if (in_array($webspaceLocale, $existingLocales)) {
             continue;
         }
         $this->nodeManager->createPath($routesPath . '/' . $webspaceLocale);
         $this->documentManager->persist($homeDocument, $webspaceLocale, ['path' => $homePath]);
     }
 }
 /**
  * @param Webspace $webspace
  * @param Portal   $portal
  */
 public function __construct(Webspace $webspace, Portal $portal)
 {
     $this->webspace = $webspace;
     $this->portal = $portal;
     $message = 'The portal "' . $portal->getKey() . '" in the webspace definition "' . $webspace->getKey() . '" ' . 'has multiple default localizations';
     parent::__construct($message, 0);
 }
 /**
  * @param Webspace $portal
  * @param string   $urlPattern
  */
 public function __construct(Webspace $portal, $urlPattern)
 {
     $this->webspace = $portal;
     $this->urlPattern = $urlPattern;
     $message = 'The url pattern "' . $urlPattern . '" in the webspace definition "' . $portal->getKey() . '" ' . 'has not specified the required attributes (either with xml attributes or as placeholders in the pattern)';
     parent::__construct($message, 0);
 }
 /**
  * @param Webspace $webspace
  * @param Portal   $portal
  */
 public function __construct(Webspace $webspace, Portal $portal)
 {
     $this->webspace = $webspace;
     $this->portal = $portal;
     $message = 'The portal "' . $portal->getKey() . '" in the webspace definition "' . $webspace->getKey() . '" ' . 'has not specified the required attributes (a default localization)';
     parent::__construct($message, 0);
 }
Example #5
0
 /**
  * Returns key of webspace.
  */
 public function getWebspaceKey()
 {
     if (null === $this->webspace) {
         return;
     }
     return $this->webspace->getKey();
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function getUrls(Webspace $webspace, $environment)
 {
     $urls = [];
     foreach ($this->customUrlManager->findUrls($webspace->getKey()) as $customUrl) {
         $urls[] = new Url($customUrl, $environment);
     }
     return $urls;
 }
Example #7
0
 private function initializeWebspace(OutputInterface $output, Webspace $webspace)
 {
     $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']);
     $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']);
     $webspaceLocales = [];
     foreach ($webspace->getAllLocalizations() as $localization) {
         $webspaceLocales[] = $localization->getLocale();
     }
     $homeType = $webspace->getDefaultTemplate('home');
     $existingLocales = [];
     $homeDocument = null;
     if ($this->nodeManager->has($homePath)) {
         $homeDocument = $this->documentManager->find($homePath, null, ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]);
         $existingLocales = $this->inspector->getLocales($homeDocument);
     }
     foreach ($webspaceLocales as $webspaceLocale) {
         if (in_array($webspaceLocale, $existingLocales)) {
             $output->writeln(sprintf('  [ ] <info>homepage</info>: %s (%s)', $homePath, $webspaceLocale));
             continue;
         }
         $output->writeln(sprintf('  [+] <info>homepage</info>: [%s] %s (%s)', $homeType, $homePath, $webspaceLocale));
         $persistOptions = ['ignore_required' => true];
         if (!$homeDocument) {
             $homeDocument = new HomeDocument();
             $persistOptions['path'] = $homePath;
             $persistOptions['auto_create'] = true;
         } else {
             $homeDocument = $this->documentManager->find($homePath, $webspaceLocale, ['load_ghost_content' => false]);
         }
         $homeDocument->setTitle('Homepage');
         $homeDocument->setStructureType($homeType);
         $this->documentManager->persist($homeDocument, $webspaceLocale, $persistOptions);
         $this->documentManager->publish($homeDocument, $webspaceLocale);
         $routePath = $routesPath . '/' . $webspaceLocale;
         try {
             $routeDocument = $this->documentManager->find($routePath);
         } catch (DocumentNotFoundException $e) {
             $routeDocument = $this->documentManager->create('route');
         }
         $routeDocument->setTargetDocument($homeDocument);
         $this->documentManager->persist($routeDocument, $webspaceLocale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($routeDocument, $webspaceLocale);
     }
     $this->documentManager->flush();
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 protected function doEnhance(CustomUrlBehavior $customUrl, Webspace $webspace, array $defaults, Request $request)
 {
     $seo = ['noFollow' => $customUrl->isNoFollow(), 'noIndex' => $customUrl->isNoIndex()];
     if ($customUrl->isCanonical()) {
         $resourceSegment = $customUrl->getTargetDocument()->getResourceSegment();
         $seo['canonicalUrl'] = $this->webspaceManager->findUrlByResourceLocator($resourceSegment, $defaults['_environment'], $customUrl->getTargetLocale(), $webspace->getKey());
     }
     return ['_seo' => $seo];
 }
Example #9
0
 /**
  * Upgrade a single webspace.
  *
  * @param Webspace $webspace
  */
 private function upgradeWebspace(Webspace $webspace)
 {
     $sessionManager = $this->container->get('sulu.phpcr.session');
     $node = $sessionManager->getContentNode($webspace->getKey());
     foreach ($webspace->getAllLocalizations() as $localization) {
         $locale = $localization->getLocalization();
         $propertyName = $this->getPropertyName(self::SHADOW_ON_PROPERTY, $locale);
         $this->upgradeNode($node, $propertyName, $locale);
     }
 }
Example #10
0
 private function generateDefaultTemplates(Theme $theme)
 {
     $expected = ['page', 'homepage'];
     $found = [];
     $nodes = $this->xpath->query('/x:webspace/x:theme/x:default-templates/x:default-template');
     foreach ($nodes as $node) {
         /* @var \DOMNode $node */
         $template = $node->nodeValue;
         $type = $node->attributes->getNamedItem('type')->nodeValue;
         $theme->addDefaultTemplate($type, $template);
         $found[] = $type;
     }
     foreach ($expected as $item) {
         if (!in_array($item, $found)) {
             throw new ExpectedDefaultTemplatesNotFound($this->webspace->getKey(), $expected, $found);
         }
     }
     return $theme;
 }
Example #11
0
 /**
  * Generates the default templates for the webspace.
  *
  * @param Webspace $webspace
  *
  * @return Webspace
  *
  * @throws ExpectedDefaultTemplatesNotFound
  */
 protected function generateDefaultTemplates(Webspace $webspace)
 {
     $expected = ['page', 'home'];
     foreach ($this->xpath->query('/x:webspace/x:theme/x:default-templates/x:default-template') as $node) {
         /* @var \DOMNode $node */
         $template = $node->nodeValue;
         $type = $node->attributes->getNamedItem('type')->nodeValue;
         $webspace->addDefaultTemplate($type, $template);
         if ($type === 'homepage') {
             $webspace->addDefaultTemplate('home', $template);
         }
     }
     $found = array_keys($webspace->getDefaultTemplates());
     foreach ($expected as $item) {
         if (!in_array($item, $found)) {
             throw new ExpectedDefaultTemplatesNotFound($this->webspace->getKey(), $expected, $found);
         }
     }
     return $webspace;
 }
 /**
  * @param Webspace $webspace
  */
 public function __construct(Webspace $webspace)
 {
     $this->webspace = $webspace;
     $message = 'The webspace definition for "' . $webspace->getKey() . '" has no default localization';
     parent::__construct($message, 0);
 }
 /**
  * @param Webspace $webspace
  */
 public function __construct(Webspace $webspace)
 {
     parent::__construct('The webspace definition for "' . $webspace->getKey() . '" has locales which are not used in any portal');
     $this->webspace = $webspace;
 }
Example #14
0
 /**
  * @param Webspace $webspace
  */
 public function __construct(Webspace $webspace, $customUrl)
 {
     parent::__construct('The custom-url "' . $customUrl . '" for "' . $webspace->getKey() . '" has no placeholder');
     $this->customUrl = $customUrl;
     $this->webspace = $webspace;
 }
 private function upgradeNode(StructureBridge $page, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0)
 {
     /** @var SessionManagerInterface $sessionManager */
     $sessionManager = $this->getContainer()->get('sulu.phpcr.session');
     $session = $sessionManager->getSession();
     $node = $session->getNodeByIdentifier($page->getUuid());
     /** @var RlpStrategyInterface $strategy */
     $strategy = $this->getContainer()->get('sulu.content.rlp.strategy.tree');
     /** @var ResourceLocator $resourceLocator */
     $resourceLocator = $this->getContainer()->get('sulu.content.type.resource_locator');
     if (!$page->hasTag('sulu.rlp')) {
         return;
     }
     $property = $page->getPropertyByTagName('sulu.rlp');
     if ($property->getContentTypeName() !== 'resource_locator' && $page->getNodeType() !== Structure::NODE_TYPE_CONTENT) {
         return;
     }
     $transProperty = new TranslatedProperty($property, $localization->getLocalization(), $this->getContainer()->getParameter('sulu.content.language.namespace'));
     try {
         // load value
         $rl = $strategy->loadByContent($node, $webspace->getKey(), $localization->getLocalization());
         // save value
         $property->setValue($rl);
         $resourceLocator->write($node, $transProperty, 1, $webspace->getKey(), $localization->getLocalization());
         $session->save();
         $prefix = '   ';
         for ($i = 0; $i < $depth; ++$i) {
             $prefix .= '-';
         }
         $output->writeln($prefix . '> "' . $page->getPropertyValue('title') . '": ' . $rl);
     } catch (ResourceLocatorNotFoundException $ex) {
     }
 }
 /**
  * @param Webspace $webspace
  */
 public function __construct(Webspace $webspace)
 {
     $this->webspace = $webspace;
     $message = 'The webspace definition for "' . $webspace->getKey() . '" has has multiple default segment';
     parent::__construct($message, 0);
 }
 private function upgradeNode(NodeInterface $node, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0)
 {
     $locale = $localization->getLocale();
     $localizedTemplatePropertyName = $this->propertyEncoder->localizedSystemName('template', $locale);
     if (!$node->hasProperty($localizedTemplatePropertyName)) {
         return;
     }
     $structureMetadata = $this->structureMetadataFactory->getStructureMetadata($this->metadataFactory->getMetadataForPhpcrNode($node)->getAlias(), $node->getPropertyValue($localizedTemplatePropertyName));
     $property = $structureMetadata->getPropertyByTagName('sulu.rlp');
     if (!$property) {
         return;
     }
     $nodeType = $node->getPropertyValue($this->propertyEncoder->localizedSystemName('nodeType', $locale));
     if ($property->getContentTypeName() !== 'resource_locator' && $nodeType !== Structure::NODE_TYPE_CONTENT) {
         return;
     }
     $baseRoutePath = $this->sessionManager->getRoutePath($webspace->getKey(), $localization->getLocale());
     foreach ($node->getReferences('sulu:content') as $routeProperty) {
         if (strpos($routeProperty->getPath(), $baseRoutePath) !== 0) {
             continue;
         }
         $routeNode = $routeProperty->getParent();
         if ($routeNode->getPropertyValue('sulu:history') === true) {
             continue;
         }
         $resourceLocator = substr($routeNode->getPath(), strlen($baseRoutePath));
         if ($resourceLocator) {
             // only set if resource locator is not empty
             // if the resource locator is empty it is the homepage, whose url should not be changed
             $node->setProperty($this->propertyEncoder->localizedContentName($property->getName(), $locale), $resourceLocator);
             $prefix = '   ';
             for ($i = 0; $i < $depth; ++$i) {
                 $prefix .= '-';
             }
             $title = $node->getPropertyValue($this->propertyEncoder->localizedContentName('title', $locale));
             $output->writeln($prefix . '> "' . $title . '": ' . $resourceLocator);
         }
         break;
     }
 }
Example #18
0
 /**
  * Dump given webspace.
  *
  * @param Webspace $webspace
  */
 private function dumpWebspace(Webspace $webspace)
 {
     foreach ($webspace->getAllLocalizations() as $localization) {
         $this->output->writeln(sprintf(' - %s (%s)', $webspace->getKey(), $localization->getLocale()));
         $this->dumpPortalInformations($this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale($webspace->getKey(), $localization->getLocale(), $this->environment));
     }
 }
 /**
  * Extract portal-information and add them to serialization.
  *
  * @param Webspace $webspace
  * @param Context $context
  * @param JsonSerializationVisitor $visitor
  */
 private function appendPortalInformation(Webspace $webspace, Context $context, JsonSerializationVisitor $visitor)
 {
     $portalInformation = $this->webspaceManager->getPortalInformationsByWebspaceKey($this->environment, $webspace->getKey());
     $portalInformation = $context->accept(array_values($portalInformation));
     $visitor->addData('portalInformation', $portalInformation);
 }