Skip to content

Instantly share code, notes, and snippets.

@wazum
Last active February 10, 2020 11:52
Show Gist options
  • Save wazum/68b5058a6da8e4a94809d1d2ba69e477 to your computer and use it in GitHub Desktop.
Save wazum/68b5058a6da8e4a94809d1d2ba69e477 to your computer and use it in GitHub Desktop.
TYPO3 9.5+ routing for news (TypoScript hrDate = 0) and eventnews (TypoScript hrDate = 1)
routeEnhancers:
News:
type: Extbase
limitToPages: …
extension: News
plugin: Pi1
routes:
-
routePath: '/{localized_page_identifier}/{news_page}'
_controller: 'News::list'
_arguments:
news_page: '@widget_0/currentPage'
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
defaultController: 'News::detail'
defaults:
news_page: '0'
aspects:
localized_page_identifier:
type: LocaleModifier
default: 'page'
localeMap:
-
locale: 'de_*'
value: 'seite'
news_page:
type: StaticIntegerRangeMapper
start: 1
end: 500
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
NewsWithDate:
type: Extbase
limitToPages: …
extension: News
plugin: Pi1
routes:
-
routePath: '/{news_year}/{news_month}/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
news_year: year
news_month: month
defaultController: 'News::detail'
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
news_month:
type: StaticPaddedRangeMapper
start: '1'
end: '31'
padString: '0'
padLength: 2
# STR_PAD_LEFT = 0
padType: 0
news_year:
type: StaticIntegerRangeMapper
start: 2010
end: 2030
requirements:
news_title: \d+
year: '^20[0-9]{2}$'
month: '^[01][0-9]$'
class EventLinkViewHelper extends LinkViewHelper
{
/**
* Render link to news item or internal/external pages.
*
* Adds the hrDate settings to create links with a date.
*
* @return string link
*/
public function render(): string
{
/** @var News $newsItem */
$newsItem = $this->arguments['newsItem'];
$settings = $this->arguments['settings'] ?? [];
$uriOnly = $this->arguments['uriOnly'];
$configuration = $this->arguments['configuration'];
$content = $this->arguments['content'];
ArrayUtility::mergeRecursiveWithOverrule($settings, [
'link' => [
'hrDate' => [
'_typoScriptNodeValue' => 1,
'day' => '',
'month' => 'm',
'year' => 'Y'
]
]
]);
… rest as in the original news LinkViewHelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment