Commit ddaeedd0 authored by gbyte.co's avatar gbyte.co

Issue #2996734 by gbyte.co, knyshuk.vova: Page not found opens instead correct...

Issue #2996734 by gbyte.co, knyshuk.vova: Page not found opens instead correct sitemap.xml when path prefix for URL language detection enabled
parent d1c4d43e
...@@ -246,3 +246,9 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) { ...@@ -246,3 +246,9 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
} }
} }
/**
* Implements hook_language_negotiation_info_alter().
*/
function simple_sitemap_language_negotiation_info_alter(&$negotiation_info) {
$negotiation_info['language-url']['class'] = 'Drupal\simple_sitemap\Plugin\LanguageNegotiation\SimplesitemapLanguageNegotiationUrl';
}
...@@ -16,7 +16,7 @@ class PathProcessorSitemapVariant implements InboundPathProcessorInterface { ...@@ -16,7 +16,7 @@ class PathProcessorSitemapVariant implements InboundPathProcessorInterface {
*/ */
public function processInbound($path, Request $request) { public function processInbound($path, Request $request) {
$args = explode('/', $path); $args = explode('/', $path);
if (count($args) === 3 && $args[0] === '' && !empty($args[1]) && $args[2] === 'sitemap.xml') { if (count($args) === 3 && $args[2] === 'sitemap.xml') {
$path = '/sitemaps/' . $args[1] . '/sitemap.xml'; $path = '/sitemaps/' . $args[1] . '/sitemap.xml';
} }
......
<?php
namespace Drupal\simple_sitemap\Plugin\LanguageNegotiation;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Symfony\Component\HttpFoundation\Request;
/**
* {@inheritdoc}
*/
class SimplesitemapLanguageNegotiationUrl extends LanguageNegotiationUrl {
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
$config = $this->config->get('language.negotiation')->get('url');
if ($config['source'] === LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
$args = explode('/', $path);
if (count($args) === 4 && $args[1] === 'sitemaps' && $args[3] === 'sitemap.xml') {
return $path;
}
}
return parent::processOutbound($path, $options, $request, $bubbleable_metadata);
}
}
...@@ -194,7 +194,7 @@ class Simplesitemap { ...@@ -194,7 +194,7 @@ class Simplesitemap {
/** /**
* @param array|string|true|null $variants * @param array|string|true|null $variants
* array: Array of variants to be set. * array: Array of variants to be set.
* string: A particular variant will be set. * string: A particular variant to be set.
* null: Default variant will be set. * null: Default variant will be set.
* true: All existing variants will be set. * true: All existing variants will be set.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment