Actions
Feature #101388
openAdd possibility to modify "canonical" tag even from within uncached extbase controller action
Status:
New
Priority:
Should have
Assignee:
-
Category:
SEO
Target version:
-
Start date:
2023-07-19
Due date:
% Done:
0%
Estimated time:
PHP Version:
7.4
Tags:
seo, canonical, uncached, extbase, controller
Complexity:
Sprint Focus:
Description
Currently it is not possible to manually modify the "canonical" tag from within an uncached extbase controller action. Canonical can only be modified when action is cached by setting "$GLOBALS['TSFE']->page['canonical_link']". The only possibility to modify the tag even when in an uncached context is to use the "ModifyUrlForCanonicalTagEvent" (EXT:seo) like this:
class FilterSeminarEventsCanonicalEventListener
{
public function __invoke(ModifyUrlForCanonicalTagEvent $event): void
{
if($params = $this->getServerRequest()->getQueryParams()['tx_myext_seminar']) {
if($params['action'] == 'filterSeminarEvents') {
$seminarUid = (int) $params['seminar'];
$locationUid = (int) $params['location'];
$eventUid = (int) $params['event'];
if($seminarUid > 0 && ($locationUid > 0 || $eventUid > 0)) {
/** @var Site $site */
$site = $this->getServerRequest()->getAttribute('site');
$parameters = [
'tx_myext_seminar' => [
'action' => 'show',
'controller' => 'Seminars\Seminar',
'seminar' => $seminarUid
]
];
$url = (string) $site->getRouter()->generateUri($this->getTypoScriptFrontendController()->id, $parameters);
$event->setUrl($url);
}
}
}
}
/**
* Returns the typoScriptFrontendController
*
* @return TypoScriptFrontendController
*/
private function getTypoScriptFrontendController()
{
return $GLOBALS['TSFE'];
}
/**
* Returns serverRequest
*
* @return ServerRequest
*/
private function getServerRequest()
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
But in addition, there should be an alternate and easier way to modify the canonical directly from e.g. a controller action. Perhaps any implementation similar to PageTitle API or MetaTag API could be added.
Updated by Chris Müller over 1 year ago
- Tracker changed from Bug to Feature
- TYPO3 Version deleted (
10)
Actions