Skip to content

Instantly share code, notes, and snippets.

Last active August 25, 2021 12:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generate link to single news with date in path segment and ignore it in resolve
namespace Cp\CpSitepackage\Routing\Aspect;
class DateFormatter
public function format($value, $format = 'd.m.Y'): string
return date($format, $value);
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(function () {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['EvowebPersistedPatternMapper'] =
type: Extbase
- 334
extension: News
plugin: Pi1
- routePath: '/{news_title}'
_controller: 'News::detail'
news_title: news
- routePath: '/{page}'
_controller: 'News::list'
page: '@widget_0/currentPage'
defaultController: 'News::detail'
page: '0'
news_title: '.+'
page: '\d+'
type: EvowebPersistedPatternMapper
tableName: 'tx_news_domain_model_news'
# no capture group for date as we dont use it for record resolving
routeFieldPattern: '^(\d+-\d+-\d+)-(?P<path_segment>.+)$'
routeFieldResult: '{datetime}-{path_segment}'
formatter: Evoweb\CpSitepackage\Routing\Aspect\DateFormatter
format: Y-m-d
namespace Evoweb\CpSitepackage\Routing\Aspect;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class PersistedPatternMapper extends \TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper
* @param array|null $result
* @return string|null
* @throws \InvalidArgumentException
protected function createRouteResult(?array $result): ?string
if ($result === null) {
return $result;
$substitutes = [];
foreach ($this->routeFieldResultNames as $fieldName) {
if (!isset($result[$fieldName])) {
return null;
$routeFieldName = '{' . $fieldName . '}';
if (isset($this->settings['formattedFields']) && isset($this->settings['formattedFields'][$fieldName])) {
$formatConfig = $this->settings['formattedFields'][$fieldName];
$formatter = GeneralUtility::makeInstance($formatConfig['formatter']);
$substitutes[$routeFieldName] = $formatter->format($result[$fieldName], $formatConfig['format']);
} else {
$substitutes[$routeFieldName] = $result[$fieldName];
return str_replace(
Copy link

klodeckl commented Feb 4, 2021

This is what I’m looking for. Can you also post DateFormatter.php?

Copy link

garbast commented Feb 4, 2021

Never thought, that a simple date() call would be too difficulty to figure it out on your own.

Copy link

klodeckl commented Feb 4, 2021

I figured it out but something is missing cause I get a page not found when accessing a generated link.

Copy link

klodeckl commented Feb 4, 2021

Solved, a character was missing in the pattern.

Copy link

Thank's a lot for this!

I spent hours looking for a way to get the date in the news url, because the routing via and the GET parameters year, month and day results in this error:
"Possible range of all mappers is larger than 10000 items
Using the StaticRangeMapper is strictly limited to 1000 items per a single range and 10000 items per routing enhancer."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment