Merge branch 'feature/sitemap' into develop
This commit is contained in:
commit
bb7acbd6de
|
@ -14,19 +14,20 @@ class SitemapController extends AbstractController
|
|||
/**
|
||||
* @Route("/sitemap.xml", name="sitemap")
|
||||
*/
|
||||
public function sitemap(Request $request, NavigationRepositoryQuery $navigationRepositoryQuery, SitemapBuilder $builder): Response
|
||||
public function sitemap(Request $request, NavigationRepositoryQuery $query, SitemapBuilder $builder): Response
|
||||
{
|
||||
$navigations = $navigationRepositoryQuery
|
||||
->whereDomain($request->getHost())
|
||||
->find()
|
||||
;
|
||||
$navigations = $query->create()->find();
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($navigations as $navigation) {
|
||||
if (!$navigation->matchDomain($request->getHost())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$items = array_merge(
|
||||
$items,
|
||||
$builder->build($navigation)
|
||||
$builder->build($navigation, $request->getHost())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -240,4 +240,23 @@ class Navigation implements EntityInterface
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function matchDomain(string $domain): bool
|
||||
{
|
||||
if ($domain === $this->getDomain()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->getAdditionalDomains() as $additionalDomain) {
|
||||
if ('domain' === $additionalDomain['type'] && $additionalDomain['domain'] === $domain) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('regexp' === $additionalDomain['type'] && preg_match('#'.$additionalDomain['domain'].'#', $domain) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class SitemapBuilder
|
|||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function build(Navigation $navigation): array
|
||||
public function build(Navigation $navigation, ?string $currentDomain): array
|
||||
{
|
||||
$items = [];
|
||||
|
||||
|
@ -52,7 +52,7 @@ class SitemapBuilder
|
|||
|
||||
$nodeItems = [];
|
||||
|
||||
foreach ($this->getNodeUrls($node) as $url) {
|
||||
foreach ($this->getNodeUrls($node, $currentDomain) as $url) {
|
||||
$nodeItems[] = $this->createItem($parameters, $url);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ class SitemapBuilder
|
|||
return $items;
|
||||
}
|
||||
|
||||
public function getNodeUrls(Node $node)
|
||||
public function getNodeUrls(Node $node, ?string $currentDomain)
|
||||
{
|
||||
$urls = [];
|
||||
|
||||
|
@ -90,9 +90,27 @@ class SitemapBuilder
|
|||
}
|
||||
}
|
||||
} elseif (!$node->getDisableUrl() && !$node->hasAppUrl()) {
|
||||
$params = [];
|
||||
$domain = $currentDomain;
|
||||
$navigation = $node->getMenu()->getNavigation();
|
||||
|
||||
if (null === $currentDomain || $navigation->getForceDomain()) {
|
||||
$domain = $navigation->getDomain();
|
||||
}
|
||||
|
||||
$params['_domain'] = $domain;
|
||||
|
||||
foreach ($node->getParameters() as $param) {
|
||||
if ('_locale' === $param['name']) {
|
||||
$params['_locale'] = !empty($param['defaultValue'])
|
||||
? $param['defaultValue']
|
||||
: $node->getMenu()->getNavigation()->getLocale();
|
||||
}
|
||||
}
|
||||
|
||||
$urls[] = $this->urlGenerator->generate(
|
||||
$node->getRouteName(),
|
||||
[],
|
||||
$params,
|
||||
UrlGeneratorInterface::ABSOLUTE_URL
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue