Problem/Motivation
Attempting to run this on recently updated Drupal 10 site with PHP 8.1 I receive this error when running the sitemap rebuild:
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /batch?id=526&op=do_nojs&op=do
StatusText: parsererror
ResponseText: Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /app/web/modules/contrib/xmlsitemap/src/XmlSitemapGenerator.php on line 281
{"status":true,"percentage":"70","message":"Completed 7 of 10.","label":"Generated \u003Cem class=\u0022placeholder\u0022\u003Ehttps:\/\/MYSITE.lndo.site\/sitemap.xml?page=1\u003C\/em\u003E with 5000 links."}
Proposed resolution
The offending code is:
$url_options += [
'absolute' => TRUE,
'base_url' => rtrim(Settings::get('xmlsitemap_base_url', $this->state->get('xmlsitemap_base_url')), '/'),
'language' => $this->languageManager->getDefaultLanguage(),
// @todo Figure out a way to bring back the alias preloading optimization.
// 'alias' => $this->config->get('prefetch_aliases'),
'alias' => FALSE,
];
This might be a reasonable solution, although I don't know where that null value was creeping in, in the first place.
$lastmod_format = $this->config->get('lastmod_format');
$url_options = $sitemap->uri['options'];
$base_url = Settings::get('xmlsitemap_base_url', $this->state->get('xmlsitemap_base_url'));
if ($base_url === null) {
$base_url = '';
}
$url_options += [
'absolute' => TRUE,
'base_url' => rtrim($base_url, '/'),
'language' => $this->languageManager->getDefaultLanguage(),
'alias' => FALSE,
];
The above change did resolve my issues, I was just wondering if I should fix it elsewhere?