Skip to content
Snippets Groups Projects
Commit 5e21823f authored by Kevin Appelt's avatar Kevin Appelt Committed by Georg Ringer
Browse files

[FEATURE] Add possibility to configure the path to sitemap xslFile

The xsl file to create a layout for a XML sitemap can now be configured
on three levels:

1. for all sitemaps
2. for all sitemaps of a certain sitemapType
3. for a specific sitemap

The value is inherited until it is overwritten.
If no value is specified at all, EXT:seo/Resources/Public/CSS/Sitemap.xsl
is used as default like before.

Resolves: #88147
Releases: master
Change-Id: I1c5212a1c9fe4226100de8f4bd0f84d70b89fcf5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62121


Tested-by: default avatarRichard Haeser <richard@maxserv.com>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: default avatarRichard Haeser <richard@maxserv.com>
Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
parent a8da4b27
Branches
Tags
No related merge requests found
.. include:: ../../Includes.txt
.. highlight:: typoscript
==========================================================================
Feature: #88147 - Add possibility to configure the path to sitemap xslFile
==========================================================================
See :issue:`88147`
Description
===========
The xsl file to create a layout for a XML sitemap can now be configured on three levels:
1. for all sitemaps::
plugin.tx_seo.config.xslFile = EXT:myext/Resources/Public/CSS/mySite.xsl
2. for all sitemaps of a certain sitemapType::
plugin.tx_seo.config.<sitemapType>.sitemaps.xslFile = EXT:myext/Resources/Public/CSS/mySite.xsl
3. for a specific sitemap::
plugin.tx_seo.config.<sitemapType>.sitemaps.<sitemap>.config.xslFile = EXT:myext/Resources/Public/CSS/mySite.xsl
Impact
======
The value is inherited until it is overwritten.
If no value is specified at all, :file:`EXT:seo/Resources/Public/CSS/Sitemap.xsl` is used as default like before.
.. index:: Frontend, TypoScript, ext:seo
......@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Seo\XmlSitemap;
*/
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
......@@ -50,12 +49,6 @@ class XmlSitemapRenderer
{
$this->configuration = $this->getConfiguration();
$this->view = $this->getStandaloneView();
$this->view->assign(
'xslFile',
PathUtility::stripPathSitePrefix(
ExtensionManagementUtility::extPath('seo', 'Resources/Public/CSS/Sitemap.xsl')
)
);
}
/**
......@@ -70,6 +63,7 @@ class XmlSitemapRenderer
$request = $GLOBALS['TYPO3_REQUEST'];
$this->view->assign('type', $GLOBALS['TSFE']->type);
$sitemapType = $typoScriptConfiguration['sitemapType'] ?? 'xmlSitemap';
$this->view->assign('xslFile', $this->getXslFilePath($sitemapType));
if (!empty($sitemap = $request->getQueryParams()['sitemap'])) {
return $this->renderSitemap($request, $sitemap, $sitemapType);
}
......@@ -139,6 +133,7 @@ class XmlSitemapRenderer
$template = $sitemapConfig['config']['template'] ?: 'Sitemap';
$this->view->setTemplate($template);
$this->view->assign('xslFile', $this->getXslFilePath($sitemapType, $sitemap));
$this->view->assign('items', $items);
$this->view->assign('sitemapType', $sitemapType);
......@@ -164,6 +159,19 @@ class XmlSitemapRenderer
return $view;
}
/**
* @param string|null $sitemapType
* @param string|null $sitemap
* @return string
*/
protected function getXslFilePath(string $sitemapType = null, string $sitemap = null): string
{
$path = $this->configuration['config']['xslFile'] ?? 'EXT:seo/Resources/Public/CSS/Sitemap.xsl';
$path = ($sitemapType !== null) ? ($this->configuration['config'][$sitemapType]['sitemaps']['xslFile'] ?? $path) : $path;
$path = ($sitemapType !== null && $sitemap !== null) ? ($this->configuration['config'][$sitemapType]['sitemaps'][$sitemap]['config']['xslFile'] ?? $path) : $path;
return PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($path));
}
/**
* Get the whole typoscript array
* @return array
......
......@@ -36,11 +36,17 @@ plugin.tx_seo {
}
config {
# Here you can override the xslFile for all sitemaps
# xslFile = EXT:seo/Resources/Public/CSS/Sitemap.xsl
xmlSitemap {
sitemaps {
# Here you can override the xslFile for all sitemaps of a certain sitemapType
# xslFile = EXT:seo/Resources/Public/CSS/Sitemap.xsl
pages {
provider = TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider
config {
# Here you can override the xslFile for a single sitemap
# xslFile = EXT:seo/Resources/Public/CSS/Sitemap.xsl
excludedDoktypes = {$plugin.tx_seo.settings.xmlSitemap.sitemaps.pages.excludedDoktypes}
additionalWhere = {$plugin.tx_seo.settings.xmlSitemap.sitemaps.pages.additionalWhere}
}
......
plugin.tx_seo {
config {
xslFile = EXT:seo/Tests/Functional/Fixtures/XslFile1.xsl
}
}
plugin.tx_seo {
config {
xmlSitemap.sitemaps.xslFile = EXT:seo/Tests/Functional/Fixtures/XslFile2.xsl
}
}
plugin.tx_seo {
config {
xslFile = EXT:seo/Tests/Functional/Fixtures/XslFile1.xsl
xmlSitemap {
sitemaps {
records {
config.xslFile = EXT:seo/Tests/Functional/Fixtures/XslFile3.xsl
}
}
}
}
}
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Seo\Tests\Functional\XmlSitemap;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
class XmlSitemapXslTest extends AbstractTestCase
{
/**
* @var string[]
*/
protected $coreExtensionsToLoad = [
'core', 'frontend', 'seo'
];
protected function setUp(): void
{
parent::setUp();
$this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml');
}
/**
* @test
* @dataProvider getXslFilePaths
*/
public function checkIfDefaultSitemapReturnsDefaultXsl($typoscriptSetupFiles, $sitemap, $xslFilePath): void
{
$this->setUpFrontendRootPage(
1,
[
'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
'setup' => $typoscriptSetupFiles
]
);
$this->writeSiteConfiguration(
'website-local',
$this->buildSiteConfiguration(1, 'http://localhost/'),
[
$this->buildDefaultLanguageConfiguration('EN', '/')
]
);
$config = [
'id' => 1,
'type' => 1533906435
];
if (!empty($sitemap)) {
$config['sitemap'] = $sitemap;
}
$response = $this->executeFrontendRequest(
(new InternalRequest('http://localhost/'))->withQueryParameters($config)
);
self::assertRegExp('/<\?xml-stylesheet type="text\/xsl" href="' . $xslFilePath . '"\?>/', (string)$response->getBody());
}
public function getXslFilePaths()
{
return [
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'
],
'',
'\/typo3\/sysext\/seo\/Resources\/Public\/CSS\/Sitemap.xsl'
],
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/sitemap-xsl1.typoscript'
],
'',
'\/typo3\/sysext\/seo\/Tests\/Functional\/Fixtures\/XslFile1.xsl'
],
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/sitemap-xsl2.typoscript'
],
'',
'\/typo3\/sysext\/seo\/Tests\/Functional\/Fixtures\/XslFile2.xsl'
],
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
'EXT:seo/Tests/Functional/Fixtures/sitemap-xsl3.typoscript'
],
'',
'\/typo3\/sysext\/seo\/Tests\/Functional\/Fixtures\/XslFile1.xsl'
],
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
'EXT:seo/Tests/Functional/Fixtures/sitemap-xsl3.typoscript'
],
'records',
'\/typo3\/sysext\/seo\/Tests\/Functional\/Fixtures\/XslFile3.xsl'
],
[
[
'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
'EXT:seo/Tests/Functional/Fixtures/records.typoscript',
'EXT:seo/Tests/Functional/Fixtures/sitemap-xsl3.typoscript'
],
'pages',
'\/typo3\/sysext\/seo\/Tests\/Functional\/Fixtures\/XslFile1.xsl'
],
];
}
}
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