public function createFromRequest(Request $request)
 {
     $originalPath = $request instanceof CmsRequest ? $request->originalPath() : $request->path();
     $scope = $this->scopeDetector->detectScope($request);
     try {
         // Find matching page
         if (!($node = $this->getFirstMatchingNode($scope, $originalPath))) {
             return $this->createDeactivated($scope, $originalPath);
         }
     } catch (DomainException $e) {
         // if db is empty
         return $this->createDeactivated($scope, $originalPath);
     }
     $cmsPath = new CmsPath();
     $cmsPath->setOriginalPath($originalPath);
     $cmsPath->setIsCmsPath(TRUE);
     $cmsPath->setMatchedNode($node);
     $cmsPath->setFallbackNode($this->getFallbackNode($scope));
     $cmsPath->setCmsPathPrefix($this->cleanPathPrefix($scope->getPathPrefix()));
     $cmsPath->setTreeScope($scope);
     $pageType = $this->getPageType($node);
     $cmsPath->setPageType($pageType);
     $targetPath = $pageType->getTargetPath();
     $nodePath = $this->cleanHomeSegment($node->getPath());
     $originalPath = $this->cleanHomeSegment($originalPath);
     $cmsPath->setNodePath($node->getPath());
     $cmsPath->setRoutePath($targetPath);
     $rewrittenPath = trim($this->replacePathHead($nodePath, $targetPath, $originalPath), '/');
     $subPath = trim($this->replacePathHead($nodePath, '', $originalPath), '/');
     if (!$rewrittenPath) {
         $rewrittenPath = '/';
     }
     $rewrittenPath = $this->changePathWhenNotGet($request, $rewrittenPath);
     $cmsPath->setRewrittenPath($rewrittenPath);
     $cmsPath->setSubPath($subPath);
     return $cmsPath;
 }