问题
I'm currenty trying to implement a custom RouteEnhancer.
Is it just me, or is the documentation horribly incomplete again? I haven't been able to find any information about custom enhancers in TYPO3 other than a meager paragraph in the changelog entry, where can I get more information about these? I can't event find them in the API documentation.
The relevant part of my domain model in my extension is Termin
and Veranstaltung
.
Theres a n to 1
relation type from termin->veranstaltung
. My Veranstaltung->showAction()
accepts a termin
as parameter. I've started with the default PersistedAliasMapper and that worked okay for the uid
s of Termin
. Unfortunately the actual title is in the Veranstaltung
entity.
I've come up with these simple converters and set my config up to use them. I have two problems:
- The generated URL still has a cHash,
veranstaltung/81?cHash=fba7f1194090a8400556257a4cfe6f3b
.
How do I get rid of that? - The resolver doesn't seem to work at all. I've debugged the return value and there seems to be nothing wrong with it.
resolve()
expects me to return the entitiesuid
as string, right?
TerminValueMapper.php:
<?php
namespace REDACTED\REDACTEDVeranstaltungen\Routing\Aspect;
use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
class TerminValueMapper implements PersistedMappableAspectInterface
{
use SiteLanguageAwareTrait;
/**
* @param string $value
*
* @return string|null
*/
public function generate(string $value): ?string
{
if($uid=intval($value)){
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_REDACTEDveranstaltungen_domain_model_termin');
$statement = $queryBuilder
->select('t.uid', 'v.titel', 'v.urltitel', 't.beginn')
->from('tx_REDACTEDveranstaltungen_domain_model_termin','t')
->leftJoin('t', 'tx_REDACTEDveranstaltungen_domain_model_veranstaltung', 'v', 't.veranstaltung = v.uid')
->where(
$queryBuilder->expr()->eq('t.uid', $uid)//$queryBuilder->createNamedParameter('horst')
)
->execute();
if($record = $statement->fetch()){
if(is_array($record) && mb_strlen(trim($record['urltitel']))){
$beginn = new \DateTime();
$beginn->setTimestamp(intval($record['beginn']));
return $uid.'--'.str_replace('--', '-', $record['urltitel'].'-'.$beginn->format('d-m-Y') );
}
}
}
return $value;
}
/**
* @param string $value
*
* @return string|null
*/
public function resolve(string $value): ?string
{
return intval(explode('--',$value)[0]);
}
}
config:
routeEnhancers:
REDACTEDveranstaltungen_veranstaltungen:
type: Extbase
extension: REDACTEDVeranstaltungen
plugin: Veranstaltungen
routes:
- { routePath: '/themenbereiche/{thema_titel}', _controller: 'Termin::search', _arguments: {'thema_titel': 'veranstaltungsarten/0'} }
- { routePath: '/veranstaltung/{termin_titel}', _controller: 'Veranstaltung::show', _arguments: {'termin_titel': 'termin'} }
aspects:
termin_titel:
#type: PersistedAliasMapper
#tableName: 'tx_REDACTEDveranstaltungen_domain_model_termin'
#routeFieldName: 'uid'
type: TerminValueMapper
thema_titel:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
回答1:
The documentation of the routing feature - specifically extending routing - can be found at https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/ExtendingRouting.html#writing-custom-enhancers
For debugging issues with cHash use the following two places as a starting point:
\TYPO3\CMS\Core\Routing\PageRouter::buildPageArguments
and Packages/TYPO3.CMS/typo3/sysext/core/Classes/Routing/PageRouter.php:311
When extending routing, pay attention of whether you need to write a custom route enhancer (if you need to manipulate how the full route looks like and gets resolved) or a custom aspect (if you want to manipulate how a single route parameter (“variable”) gets mapped and resolved). Both also have sub-types (enhancers and decorators, static or dynamic mappers) which you can find in the documentation.
来源:https://stackoverflow.com/questions/57649210/typo3-routeenhancer-with-custom-valuemapper