Issue Feature Resolved

#101388Add possibility to modify "canonical" tag even from within uncached extbase controller action

Jan Kornblum 07/19/23, 08:30 updated 11/20/26, 16:25

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.

Reviews 1

History 34

  1. Benni Mack commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-11-20T16:25:12+00:00" > 11/20/26, 16:25 </span>

    Applied in changeset commit:eaf1c6217901d02496575c3cb3fa6e840aced901.