diff --git a/public/typo3conf/ext/ep_theme/Classes/Form/AddReferrerFinisher.php b/public/typo3conf/ext/ep_theme/Classes/Form/AddReferrerFinisher.php index f75b83dd..6f5463bd 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Form/AddReferrerFinisher.php +++ b/public/typo3conf/ext/ep_theme/Classes/Form/AddReferrerFinisher.php @@ -8,8 +8,14 @@ class AddReferrerFinisher extends AbstractFinisher { protected function executeInternal() { - $referrer = 'FooBarBaz'; + // Look for key 'referrer' in frontend session + $referrer = $GLOBALS['TSFE']->fe_user->getKey('ses', 'referrer'); + if (null === $referrer) { + return; + } + + // Add textfield to form containing referrer value $field = $this->finisherContext ->getFormRuntime() ->getFormDefinition() @@ -20,10 +26,15 @@ class AddReferrerFinisher extends AbstractFinisher $field->setDataType('string'); $field->setLabel('Referrer'); + // Add finisher variable for potential later use $this->finisherContext->getFinisherVariableProvider()->add( $this->shortFinisherIdentifier, 'referrer', $referrer ); + + // Remove session key + $GLOBALS['TSFE']->fe_user->setKey('ses', 'referrer', null); + $GLOBALS['TSFE']->fe_user->storeSessionData(); } } diff --git a/public/typo3conf/ext/ep_theme/Classes/Middleware/ReferrerMiddleware.php b/public/typo3conf/ext/ep_theme/Classes/Middleware/ReferrerMiddleware.php new file mode 100644 index 00000000..35eed7a5 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Classes/Middleware/ReferrerMiddleware.php @@ -0,0 +1,39 @@ +getQueryParams(); + + if (!array_key_exists('ref', $queryParams)) { + return $handler->handle($request); + } + + $ref = $queryParams['ref']; + + /** @var SiteFinder $siteFinder */ + $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); + + try { + $site = $siteFinder->getSiteByPageId($ref); + $url = $site->getRouter()->generateUri($ref); + $GLOBALS['TSFE']->fe_user->setKey('ses', 'referrer', $url); + $GLOBALS['TSFE']->fe_user->storeSessionData(); + } + catch (SiteNotFoundException $exception) { + } + + return $handler->handle($request); + } +} diff --git a/public/typo3conf/ext/ep_theme/Configuration/RequestMiddlewares.php b/public/typo3conf/ext/ep_theme/Configuration/RequestMiddlewares.php new file mode 100644 index 00000000..ec4ed8b7 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Configuration/RequestMiddlewares.php @@ -0,0 +1,12 @@ + [ + 'ep/referrer' => [ + 'target' => \EP\EpTheme\Middleware\ReferrerMiddleware::class, + 'after' => [ + 'typo3/cms-frontend/site', + ], + ], + ], +]; diff --git a/public/typo3conf/ext/ep_theme/Configuration/Yaml/FormSetup.yaml b/public/typo3conf/ext/ep_theme/Configuration/Yaml/FormSetup.yaml deleted file mode 100644 index 255e9b4e..00000000 --- a/public/typo3conf/ext/ep_theme/Configuration/Yaml/FormSetup.yaml +++ /dev/null @@ -1,29 +0,0 @@ -TYPO3: - CMS: - Form: - persistenceManager: - allowedExtensionPaths: - 10: EXT:ep_theme/Resources/Private/Forms/ - - prototypes: - standard: - finishersDefinition: - BpnApiFinisher: - implementationClassName: 'EP\EpTheme\Form\BpnApiFinisher' - formElementsDefinition: - Form: - renderingOptions: - templateRootPaths: - 100: 'EXT:ep_theme/Resources/Private/Templates/Form/' - partialRootPaths: - 100: 'EXT:ep_theme/Resources/Private/Partials/Form/' - layoutRootPaths: - 100: 'EXT:ep_theme/Resources/Private/Layouts/Form/' - - contactform: - __inheritances: - 10: 'TYPO3.CMS.Form.prototypes.standard' - - applicationform: - __inheritances: - 10: 'TYPO3.CMS.Form.prototypes.standard'