Bug #86598
closedTypoScript for fieldToParameterMap does not work (wrong assignment Key => Value)
0%
Description
Hello Core Team,
For the current news extension (7.0.6 for TYPO3 9.5) we wanted to include the corresponding news records in the new SEO sitemap. Here I came across a bug that prevents the generated links in the news sitemap from working correctly. Namely, a defined parameter in the TypoScript is not determined correctly and therefore not included in the generated link.
This is the corresponding TypoScript:
config {
xmlSitemap {
sitemaps {
# News (Newsmitteilungen)
news {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = tx_news_domain_model_news
sortField = sorting
lastModifiedField = tstamp
#additionalWhere = AND (no_index = 0 OR no_follow = 0)
pid = 30
url {
pageId = 31
fieldToParameterMap {
uid = tx_news_pi1[news]
}
additionalGetParameters {
tx_news_pi1.controller = News
tx_news_pi1.action = detail
}
useCacheHash = 1
}
}
}
}
}
}
The problem here is the configuration for "fieldToParameterMap". Here, the current Uid of the news record should be linked to the corresponding news parameter. Unfortunately, this does not work.
After some debugging in the core code, I also came across the problem. In the file sysext/seo/Classes/XmlSitemap/RecordsXmlSitemapDataProvider.php the assignment between url part and field name is made in line 136. And this is exactly where a design mistake lies. In lines 87-92 in the same file, all news records (or any other extension, depending on the configuration of the sitemap) are determined and passed to an items array. In this case, the individual data records in this item array are assigned to the subarray 'data'. So far so good.
In the file sysext/seo/Classes/XmlSitemap/AbstractXmlSitemapDataProvider.php the function "defineUrl" is now called in line 136 and given to it the item array determined in the first file as parameter "$data". In the function, the actually problematic function "getUrlFieldParameterMap" is called with this same data array. If you debug this array in the function, you get the following content:
Array
(
[data] => Array
(
[uid] => 1
[pid] => 30
...
)
[lastMod] => 1538984469
)
The function then tries to merge the url part "tx_news_pi1 [news]" with the field "uid" from the data array in the assignment in line 136 in my example.
foreach ($this->config['url']['fieldToParameterMap'] as $field => $urlPart) {
$additionalParams[$urlPart] = $data[$field];
}
And that can not work at this point, because as the debug of the data array shows, the actual data (including the uid) can only be found in the subarray "data".
This can be fixed in the file sysext/seo/Classes/XmlSitemap/RecordsXmlSitemapDataProvider.php in line 104, in which not the complete data array is transferred, but only the subarray "data":
Current:
$additionalParams = $this->getUrlFieldParameterMap($additionalParams, $data);
Correction:
$additionalParams = $this->getUrlFieldParameterMap($additionalParams, $data['data']);
I hope my long explanation helps. ;-)