Skip to content

Commit

Permalink
fix-url-path
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-net committed Jan 10, 2025
1 parent 599a86c commit b63dfa7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Model/LandingPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public function getUrlPath()
*/
public function setUrlPath(?string $urlPath): LandingPageInterface
{
$urlPath = trim($urlPath, ' /');
return $this->setData(self::URL_PATH, $urlPath);
}

Expand Down
14 changes: 12 additions & 2 deletions src/Model/UrlRewriteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,20 @@ public function generateRewrite(UrlRewriteGeneratorInterface $page, string $suff
? $page->getUrlRewriteRequestPath()
: $page->getUrlPath() . $suffix;

$requestPath = trim($requestPath, '/');

$urlRewrite->setRequestPath($requestPath);
$urlRewritesToPersist[] = $urlRewrite;

//if requestpath ends with an /, generate an new urlrewrite without the /
if (substr($requestPath, -1) === '/') {
$urlRewrite = $this->urlRewriteFactory->create();
$urlRewrite
->setEntityType($page->getUrlRewriteEntityType())
->setEntityId($page->getUrlRewriteEntityId())
->setTargetPath($page->getUrlRewriteTargetPath())
->setStoreId($storeId);
$urlRewrite->setRequestPath(substr($requestPath, 0, -1));
$urlRewritesToPersist[] = $urlRewrite;
}
}

$this->urlPersist->replace($urlRewritesToPersist);
Expand Down

0 comments on commit b63dfa7

Please sign in to comment.