fix sitemap generator: inject current domain when it's possible

This commit is contained in:
Simon Vieille 2022-05-10 09:42:09 +02:00
parent 8e06dab2b3
commit 53280aeccd
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -69,6 +69,14 @@ class SitemapBuilder
public function getNodeUrls(Node $node, ?string $currentDomain)
{
$urls = [];
$domain = $currentDomain;
$navigation = $node->getMenu()->getNavigation();
if (null === $currentDomain || $navigation->getForceDomain()) {
$domain = $navigation->getDomain();
}
$params = ['_domain' => $domain];
try {
if ($node->hasExternalUrl()) {
@ -80,26 +88,21 @@ class SitemapBuilder
if (null === $annotation) {
$urls[] = $this->urlGenerator->generate(
$node->getRouteName(),
[],
$params,
UrlGeneratorInterface::ABSOLUTE_URL
);
} else {
$annotation->options = array_merge(
$params,
$annotation->options
);
$service = $this->container->get($annotation->service);
$method = $annotation->method;
$urls = $service->{$method}($node, $annotation->options);
}
}
} 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'])