/**
  * Add information to serialized custom-url document.
  *
  * @param ObjectEvent $event
  */
 public function onPostSerialize(ObjectEvent $event)
 {
     $customUrl = $event->getObject();
     $visitor = $event->getVisitor();
     if (!$customUrl instanceof CustomUrlDocument) {
         return;
     }
     if ($customUrl->getTargetDocument() !== null) {
         $visitor->addData('targetTitle', $customUrl->getTargetDocument()->getTitle());
     }
     $visitor->addData('customUrl', $this->generator->generate($customUrl->getBaseDomain(), $customUrl->getDomainParts()));
     $visitor->addData('creatorFullName', $this->userManager->getFullNameByUserId($customUrl->getCreator()));
     $visitor->addData('changerFullName', $this->userManager->getFullNameByUserId($customUrl->getChanger()));
 }
Beispiel #2
0
 public function current()
 {
     $row = parent::current();
     $result = [];
     foreach ($this->columns as $column) {
         $result[str_replace('a.', '', $column)] = $row->getValue($column);
     }
     $result['targetTitle'] = '';
     if (!empty($result['targetDocument']) && array_key_exists($result['targetDocument'], $this->targets)) {
         $result['targetTitle'] = $this->targets[$result['targetDocument']]['title'];
     }
     $result['domainParts'] = json_decode($result['domainParts'], true);
     $result['customUrl'] = $this->generator->generate($result['baseDomain'], $result['domainParts']);
     $result['creatorFullName'] = $this->userManager->getFullNameByUserId($result['creator']);
     $result['changerFullName'] = $this->userManager->getFullNameByUserId($result['changer']);
     return $result;
 }
Beispiel #3
0
 /**
  * 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);
     }
 }
Beispiel #4
0
 /**
  * Returns list of custom-url data-arrays.
  *
  * @param string $path
  *
  * @return \Iterator
  */
 public function findUrls($path)
 {
     $session = $this->sessionManager->getSession();
     $queryManager = $session->getWorkspace()->getQueryManager();
     $qomFactory = $queryManager->getQOMFactory();
     $queryBuilder = new QueryBuilder($qomFactory);
     $queryBuilder->addSelect('a', 'domainParts', 'domainParts')->addSelect('a', 'baseDomain', 'baseDomain');
     $queryBuilder->from($queryBuilder->qomf()->selector('a', 'nt:unstructured'));
     $queryBuilder->where($queryBuilder->qomf()->comparison($queryBuilder->qomf()->propertyValue('a', 'jcr:mixinTypes'), QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $queryBuilder->qomf()->literal('sulu:custom_url')));
     $queryBuilder->andWhere($queryBuilder->qomf()->descendantNode('a', $path));
     $query = $queryBuilder->getQuery();
     $result = $query->execute();
     return array_map(function (Row $item) {
         return $this->generator->generate($item->getValue('a.baseDomain'), json_decode($item->getValue('a.domainParts'), true));
     }, iterator_to_array($result->getRows()));
 }
 /**
  * Matches given url to portal-information.
  *
  * @param string $url
  * @param PortalInformation $portalInformation
  * @param Request $request
  *
  * @return RequestAttributes|void
  */
 private function matchCustomUrl($url, PortalInformation $portalInformation, Request $request)
 {
     $webspace = $portalInformation->getWebspace();
     $routeDocument = $this->customUrlManager->findRouteByUrl($url, $webspace->getKey());
     if (!$routeDocument) {
         return [];
     } elseif ($routeDocument->isHistory()) {
         // redirect happen => no portal is needed
         return ['customUrlRoute' => $routeDocument];
     }
     $customUrlDocument = $this->customUrlManager->findByUrl($url, $webspace->getKey(), $routeDocument->getTargetDocument()->getTargetLocale());
     if ($customUrlDocument === null || $customUrlDocument->isPublished() === false || $customUrlDocument->getTargetDocument() === null || $customUrlDocument->getTargetDocument()->getWorkflowStage() !== WorkflowStage::PUBLISHED) {
         // error happen because this custom-url is not published => no portal is needed
         return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
     }
     $localization = $this->parse($customUrlDocument->getTargetLocale());
     $portalInformations = $this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale($portalInformation->getWebspace()->getKey(), $localization->getLocalization(), $this->environment);
     if (0 === count($portalInformations)) {
         return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
     }
     return ['portalInformation' => $portalInformation, 'localization' => $localization, 'customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument, 'urlExpression' => $this->generator->generate($customUrlDocument->getBaseDomain(), $customUrlDocument->getDomainParts())];
 }