Deprecation: #110334 - AbstractXmlSitemapDataProvider
See forge#110334
Description
The class
\TYPO3\ has
been marked as deprecated and will be removed in TYPO3 v16.0.
XML sitemap data providers are services now, receiving all runtime information
as
\TYPO3\ argument of
get, see Breaking: #110334 - XML sitemap data provider interface changed. The base class only
serves the previous approach of handing over the runtime information as
constructor arguments and storing the items of a sitemap in a property.
The class is kept in TYPO3 v15 to ease the transition: Data providers extending it are still instantiated with their runtime information and keep working unchanged, which allows extensions to support TYPO3 v14 and v15 with a single implementation.
Impact
Instantiating a data provider extending
Abstract triggers a PHP
E_
error. The sitemap itself is rendered as before.
The extension scanner detects usages of the deprecated class as strong match.
Affected installations
All installations with custom extensions providing an own XML sitemap data
provider based on
Abstract.
Migration
Implement
\TYPO3\
directly instead of extending the base class. The items are collected in
get instead of the constructor, and the properties of the base
class are replaced by the
Xml argument:
// Before
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider;
class MyXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider
{
public function __construct(ServerRequestInterface $request, string $key, array $config = [], ?ContentObjectRenderer $cObj = null)
{
parent::__construct($request, $key, $config, $cObj);
$itemRepository = GeneralUtility::makeInstance(MyItemRepository::class);
foreach ($itemRepository->findAll($this->config) as $item) {
$this->items[] = [
'uid' => $item['uid'],
'lastMod' => $item['tstamp'],
];
}
}
protected function defineUrl(array $data): array
{
$data['loc'] = $this->cObj->createUrl([
'parameter' => $data['uid'],
'forceAbsoluteUrl' => 1,
]);
return $data;
}
}
// After
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemap;
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemapDataProviderInterface;
use TYPO3\CMS\Seo\XmlSitemap\XmlSitemapRequest;
final readonly class MyXmlSitemapDataProvider implements XmlSitemapDataProviderInterface
{
public function __construct(
private MyItemRepository $itemRepository,
) {}
public function getSitemap(XmlSitemapRequest $sitemapRequest): XmlSitemap
{
$items = [];
foreach ($this->itemRepository->findAll($sitemapRequest->configuration) as $item) {
$items[] = [
'uid' => $item['uid'],
'lastMod' => $item['tstamp'],
];
}
return XmlSitemap::forPage(
$items,
$sitemapRequest->page,
fn(array $item): array => $this->defineUrl($item, $sitemapRequest),
);
}
private function defineUrl(array $item, XmlSitemapRequest $sitemapRequest): array
{
$item['loc'] = $sitemapRequest->contentObjectRenderer->createUrl([
'parameter' => $item['uid'],
'forceAbsoluteUrl' => 1,
]);
return $item;
}
}
The properties of the base class are mapped as follows:
$this->keybecomes$sitemapRequest->name $this->configbecomes$sitemapRequest->configuration $this->requestbecomes$sitemapRequest->request $this->cbecomesObj $sitemapRequest->content Object Renderer $this->itemsbecomes the items handed over toXmlSitemap:: for Page () $this->numberbecomes the fourth argument ofOf Items Per Page XmlSitemap:: for Page ()
The methods
get,
get,
get and
get are not needed anymore: The returned
Xml provides the last modification date and the number of pages,
both calculated from the items of the sitemap.
Registering a sitemap in TypoScript is unchanged: Data providers are still referenced by their class name.
Extensions supporting TYPO3 v14 and v15 with a single implementation keep
extending
Abstract and migrate once support for
TYPO3 v14 is dropped.