Unverified Commit 24882844 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid
Browse files

Issue #3006295 by Dave Reid: Front page link gets reset to empty string...

Issue #3006295 by Dave Reid: Front page link gets reset to empty string (without leading slash) causing Url internal path component exceptions during generation.
parent 5159f17c
......@@ -280,7 +280,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
$this->linkStorage->save([
'type' => 'frontpage',
'id' => 0,
'loc' => '',
'loc' => '/',
'subtype' => '',
'priority' => $values['frontpage_priority'],
'changefreq' => $values['frontpage_changefreq'],
......
......@@ -157,7 +157,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
'type' => 'testing',
'subtype' => '',
'id' => 1,
'loc' => 'testing',
'loc' => '/testing',
'status' => 1,
];
$this->linkStorage->save($link);
......@@ -168,7 +168,7 @@ class XmlSitemapUnitTest extends XmlSitemapTestBase {
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
$link['priority'] = 0.5;
$link['loc'] = 'new_location';
$link['loc'] = '/new_location';
$link['status'] = 1;
$this->linkStorage->save($link);
$this->assertFlag('xmlsitemap_regenerate_needed', TRUE);
......
......@@ -253,8 +253,15 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
'xmlsitemap_link' => $link,
'xmlsitemap_sitemap' => $sitemap,
];
// Ensure every link starts with a slash.
// @see \Drupal\Core\Url::fromInternalUri()
if ($link['loc'][0] !== '/') {
trigger_error(t('The XML sitemap link path %path for @type @id is invalid because it does not start with a slash.', ['%path' => $link['loc'], '@type' => $link['type'], '@id' => $link['id']]), E_USER_ERROR);
$link['loc'] = '/' . $link['loc'];
}
// @todo Add a separate hook_xmlsitemap_link_url_alter() here?
$link['loc'] = empty($link['loc']) ? '/' : $link['loc'];
$link_url = Url::fromUri('internal:' . $link['loc'], $link_options + $url_options)->toString();
// Skip this link if it was a duplicate of the last one.
......
......@@ -141,6 +141,12 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
$link['changecount'] = 0;
}
// Throw an error with the link does not start with a slash.
// @see \Drupal\Core\Url::fromInternalUri()
if ($link['loc'][0] !== '/') {
trigger_error(t('The XML sitemap link path %path for @type @id is invalid because it does not start with a slash.', ['%path' => $link['loc'], '@type' => $link['type'], '@id' => $link['id']]), E_USER_ERROR);
}
// Check if this is a changed link and set the regenerate flag if necessary.
if (!$this->state->get('xmlsitemap_regenerate_needed')) {
$this->checkChangedLink($link, NULL, TRUE);
......
......@@ -360,3 +360,10 @@ function xmlsitemap_update_8002() {
->condition('type', 'frontpage')
->execute();
}
/**
* Update the path of the frontpage link in case it was reset again.
*/
function xmlsitemap_update_8003() {
xmlsitemap_update_8002();
}
......@@ -1880,7 +1880,7 @@ function xmlsitemap_xmlsitemap_link_info() {
*/
function xmlsitemap_xmlsitemap_link_alter(&$link) {
// Alter the frontpage priority.
if ($link['type'] == 'frontpage' || $link['loc'] == '' || $link['loc'] == Drupal::config('system.site')->get('page.front')) {
if ($link['type'] == 'frontpage' || $link['loc'] == '/' || $link['loc'] == Drupal::config('system.site')->get('page.front')) {
$link['priority'] = \Drupal::config('xmlsitemap.settings')->get('frontpage_priority');
$link['changefreq'] = \Drupal::config('xmlsitemap.settings')->get('frontpage_changefreq');
}
......@@ -1894,7 +1894,7 @@ function xmlsitemap_xmlsitemap_links() {
$links[] = [
'type' => 'frontpage',
'id' => 0,
'loc' => '',
'loc' => '/',
];
return $links;
}
......
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