From f86f9065c33922eb890b160baf02090b1e4f2f04 Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Fri, 1 Mar 2024 13:00:48 +0100 Subject: [PATCH] !!![FEATURE] Define where to save linklistener, shortener and utm-generator records via User TSConfig now Before this commit, there was a general setting in ext_conf_template.txt file for linklistenr records. And this accidentally was also used for shortener and utm-generator records in LUXenterprise. Now with the introduction of multiclient support, we want to store those records on different pages - depending on the backend user that is working with those tables. Summary: While the setting in ext_conf_template.txt file was removed, now a User TSConfig setting should be added to be_groups (or be_user) when those records should not be stored on root page (where editors normaly don't have access) like: tx_lux { defaultPage { tx_lux_domain_model_linklistener = 1 tx_luxenterprise_domain_model_shortener = 2 tx_luxenterprise_domain_model_utmgenerator_uri = 3 } } --- Classes/Utility/BackendUtility.php | 24 ++++++++++++++ Classes/Utility/ConfigurationUtility.php | 11 ------- .../ViewHelpers/Backend/UriNewViewHelper.php | 32 +++++++++++++++---- ext_conf_template.txt | 3 -- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/Classes/Utility/BackendUtility.php b/Classes/Utility/BackendUtility.php index bd19fbfd..4ef4cab9 100644 --- a/Classes/Utility/BackendUtility.php +++ b/Classes/Utility/BackendUtility.php @@ -6,6 +6,7 @@ use In2code\Lux\Domain\Model\Transfer\FilterDto; use Throwable; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Property\PropertyMapper; @@ -36,6 +37,20 @@ public static function isAdministrator(): bool return false; } + /** + * @param string $path + * @return int|string|array + */ + public static function getUserTsConfigByPath(string $path) + { + try { + return ArrayUtility::getValueByPath(self::getUserTsConfig(), $path); + } catch (Throwable $exception) { + unset($exception); + } + return ''; + } + public static function saveValueToSession(string $key, string $action, string $controller, array $data): void { self::getBackendUserAuthentication()->setAndSaveSessionData($key . $action . $controller . '_lux', $data); @@ -72,6 +87,15 @@ public static function getSessionValue(string $key, string $action, string $cont return []; } + protected static function getUserTsConfig(): array + { + $backendUserAuthentication = self::getBackendUserAuthentication(); + if ($backendUserAuthentication !== null) { + return $backendUserAuthentication->getTSConfig(); + } + return []; + } + public static function getBackendUserAuthentication(): ?BackendUserAuthentication { return $GLOBALS['BE_USER'] ?? null; diff --git a/Classes/Utility/ConfigurationUtility.php b/Classes/Utility/ConfigurationUtility.php index 3b41f2ca..5ec3e9ee 100644 --- a/Classes/Utility/ConfigurationUtility.php +++ b/Classes/Utility/ConfigurationUtility.php @@ -72,17 +72,6 @@ public static function getCategoryScoringLinkListenerClick(): int return (int)$extensionConfig['categoryScoringLinkListenerClick']; } - /** - * @return int - * @throws ExtensionConfigurationExtensionNotConfiguredException - * @throws ExtensionConfigurationPathDoesNotExistException - */ - public static function getPidLinkClickRedords(): int - { - $extensionConfig = self::getExtensionConfiguration(); - return (int)$extensionConfig['pidLinkClickRedords']; - } - /** * @return bool * @throws ExtensionConfigurationExtensionNotConfiguredException diff --git a/Classes/ViewHelpers/Backend/UriNewViewHelper.php b/Classes/ViewHelpers/Backend/UriNewViewHelper.php index d845981f..53dccfc8 100644 --- a/Classes/ViewHelpers/Backend/UriNewViewHelper.php +++ b/Classes/ViewHelpers/Backend/UriNewViewHelper.php @@ -4,10 +4,8 @@ namespace In2code\Lux\ViewHelpers\Backend; use In2code\Lux\Domain\Service\Uri\NewRecord; -use In2code\Lux\Utility\ConfigurationUtility; +use In2code\Lux\Utility\BackendUtility; use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; -use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -24,16 +22,38 @@ public function initializeArguments() /** * @return string * @throws RouteNotFoundException - * @throws ExtensionConfigurationExtensionNotConfiguredException - * @throws ExtensionConfigurationPathDoesNotExistException */ public function render(): string { $newRecord = GeneralUtility::makeInstance(NewRecord::class, $this->renderingContext); return $newRecord->get( $this->arguments['tableName'], - ConfigurationUtility::getPidLinkClickRedords(), + $this->getPageIdentifierForTable($this->arguments['tableName']), (bool)$this->arguments['addReturnUrl'] ); } + + /** + * Get page identifier from user tsconfig + * + * Example configuration in be_groups could be: + * tx_lux { + * defaultPage { + * tx_lux_domain_model_linklistener = 1 + * tx_luxenterprise_domain_model_shortener = 2 + * tx_luxenterprise_domain_model_utmgenerator_uri = 3 + * } + * } + * + * @param string $tableName + * @return int + */ + protected function getPageIdentifierForTable(string $tableName): int + { + $configuration = BackendUtility::getUserTsConfigByPath('tx_lux./defaultPage.'); + if (is_array($configuration) && array_key_exists($tableName, $configuration)) { + return (int)$configuration[$tableName]; + } + return 0; + } } diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 0423abd4..bc07ddbf 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -18,9 +18,6 @@ categoryScoringAddDownload = 20 # cat=basic//050; type=number; label= Add on click on Link Listener: Add a value to the category scoring if a lead clicks a Link Listener link categoryScoringLinkListenerClick = 20 -# cat=basic//060; type=number; label= Where to save LinkListener records: Define a page where the link listener records should be saved - relevant for editor rights -pidLinkClickRedords = 0 - # cat=module/enable/100; type=boolean; label= Disable analysis module: Turn off the analysis backend-module if you don't need it.