diff --git a/Classes/Form/FormDataProvider/UsercentricsDatabaseEditRow.php b/Classes/Form/FormDataProvider/UsercentricsDatabaseEditRow.php deleted file mode 100755 index b5b33e7..0000000 --- a/Classes/Form/FormDataProvider/UsercentricsDatabaseEditRow.php +++ /dev/null @@ -1,67 +0,0 @@ -siteConfiguration); - } - - /** - * First level of ['customData']['siteData'] to ['databaseRow'] - * - * @throws \RuntimeException - */ - public function addData(array $result): array - { - if ($result['command'] !== 'edit' || $result['tableName'] !== 'site_usercentrics') { - return $result; - } - - $siteFinder = GeneralUtility::makeInstance(SiteFinder::class, $this->siteConfiguration); - - $rootPageId = (int)($result['inlineTopMostParentUid'] ?? $result['inlineParentUid']); - try { - $rowData = $this->getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId); - $parentFieldName = $result['inlineParentFieldName']; - if (!isset($rowData[$parentFieldName])) { - throw new \RuntimeException('Field "' . $parentFieldName . '" not found', 1520886092); - } - $rowData = $rowData[$parentFieldName][$result['vanillaUid']]; - $result['databaseRow']['uid'] = $result['vanillaUid']; - } catch (SiteNotFoundException) { - $rowData = []; - } - - foreach ($rowData as $fieldName => $value) { - // Flat values only - databaseRow has no "tree" - if (!is_array($value)) { - $result['databaseRow'][$fieldName] = $value; - } - } - // All "records" are always on pid 0 - $result['databaseRow']['pid'] = 0; - return $result; - } -} diff --git a/Classes/Form/FormDataProvider/UsercentricsTcaInline.php b/Classes/Form/FormDataProvider/UsercentricsTcaInline.php deleted file mode 100755 index 7b6c490..0000000 --- a/Classes/Form/FormDataProvider/UsercentricsTcaInline.php +++ /dev/null @@ -1,53 +0,0 @@ -addInlineFirstPid($result); - foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) { - if (!$this->isInlineField($fieldConfig)) { - continue; - } - $childTableName = $fieldConfig['config']['foreign_table'] ?? ''; - if ($childTableName !== 'site_usercentrics') { - continue; - } - $result['processedTca']['columns'][$fieldName]['children'] = []; - $result = $this->resolveSiteRelatedChildren($result, $fieldName); - if (!empty($result['processedTca']['columns'][$fieldName]['config']['selectorOrUniqueConfiguration'])) { - throw new \RuntimeException('selectorOrUniqueConfiguration not implemented in sites module', 1624313533); - } - } - - return $result; - } -} diff --git a/Classes/Hooks/UsercentricsPostRenderHook.php b/Classes/Hooks/UsercentricsPostRenderHook.php deleted file mode 100755 index cb649aa..0000000 --- a/Classes/Hooks/UsercentricsPostRenderHook.php +++ /dev/null @@ -1,109 +0,0 @@ - '', - 'version' => 'loader', - 'useBlocker' => false, - ]; - - protected ?Site $site = null; - - public function __construct(protected SiteFinder $siteFinder) {} - - public function executePostRenderHook(array $params): void - { - $pageUid = $this->getRequest()->getAttribute('frontend.controller')->page['uid'] ?? 0; - if ($pageUid < 1) { - return; - } - - $siteArguments = $this->getCurrentSiteArguments($pageUid); - $id = $siteArguments['id'] ?? ''; - if ($id !== '') { - $extensionConfig = $this->getExtensionConfiguration($pageUid); - - $preload = []; - $userCentrics = []; - - // CMP 1, 2, ... - $version = $siteArguments['version'] ?? ''; - if ($config = $extensionConfig[$version] ?? false) { - $preload[] = $config['preload'] ?? ''; - $userCentrics[] = $config['template'] ?? ''; - } - - // Blocker - if ( - ($siteArguments['useBlocker'] ?? false) - && $config = $extensionConfig['block'] ?? false - ) { - $preload[] = $config['preload'] ?? ''; - $userCentrics[] = $config['template'] ?? ''; - } - - $params['titleTag'] .= str_replace('###ID###', $id, implode(LF, array_merge($preload, $userCentrics))); - } - } - - protected function getCurrentSiteArguments(int $pageUid): array - { - $siteArguments = $this->siteArguments; - - $site = $this->getSiteByPageUid($pageUid); - try { - foreach ($site->getAttribute('usercentrics') as $usercentrics) { - if (str_contains($usercentrics['applicationContext'] ?? '', (string)Environment::getContext())) { - $siteArguments = $usercentrics; - break; - } - } - } catch (\Exception) { - $siteArguments = []; - } - - return is_array($siteArguments) ? $siteArguments : []; - } - - protected function getExtensionConfiguration($pageUid): array - { - $siteSettings = $this->getSiteByPageUid($pageUid)->getSettings(); - $configuration = $siteSettings->has('ew-base') ? $siteSettings->get('ew-base') : []; - return is_array($configuration['userCentrics'] ?? false) ? $configuration['userCentrics'] : []; - } - - protected function getSiteByPageUid(int $pageUid): Site - { - if (!$this->site) { - try { - $this->site = $this->siteFinder->getSiteByPageId($pageUid); - } catch (\Exception) { - } - } - return $this->site; - } - - protected function getRequest(): ServerRequestInterface - { - return $GLOBALS['TYPO3_REQUEST']; - } -} diff --git a/Classes/Updates/GridelementsToContainerMigration.php b/Classes/Updates/GridelementsToContainerMigration.php deleted file mode 100755 index fe30844..0000000 --- a/Classes/Updates/GridelementsToContainerMigration.php +++ /dev/null @@ -1,107 +0,0 @@ -logger = $logManager->getLogger(self::class); - } - - public function getTitle(): string - { - return 'Migrate gridelements to container'; - } - - public function getDescription(): string - { - return 'Migrates content elements that are type gridelements to corresponding container elements'; - } - - public function getPrerequisites(): array - { - return [ - DatabaseUpdatedPrerequisite::class, - ]; - } - - public function updateNecessary(): bool - { - return $this->hasRecordsToUpdate(); - } - - public function executeUpdate(): bool - { - $updateSuccessful = true; - try { - $this->service->migrate(); - } catch (\Exception $exception) { - $this->logger->log(LogLevel::ERROR, $exception->getMessage()); - $updateSuccessful = false; - } - - return $updateSuccessful; - } - - protected function hasRecordsToUpdate(): bool - { - return (bool)$this->getPreparedQueryBuilder()->count('uid')->executeQuery()->fetchOne(); - } - - protected function getPreparedQueryBuilder(): QueryBuilder - { - $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME); - $queryBuilder->getRestrictions() - ->removeByType(HiddenRestriction::class) - ->removeByType(StartTimeRestriction::class) - ->removeByType(EndTimeRestriction::class); - $queryBuilder - ->from(self::TABLE_NAME) - ->where( - $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('gridelements_pi1')) - ); - return $queryBuilder; - } - - protected function getConnectionPool(): ConnectionPool - { - return GeneralUtility::makeInstance(ConnectionPool::class); - } -} diff --git a/Classes/Updates/GridelementsToContainerService.php b/Classes/Updates/GridelementsToContainerService.php deleted file mode 100755 index 0afc636..0000000 --- a/Classes/Updates/GridelementsToContainerService.php +++ /dev/null @@ -1,277 +0,0 @@ - [ - 'CType' => 'three-col-columns', - ], - '140' => [ - 'CType' => [ - 'search' => 'pi_flexform/type', - 'matches' => [ - 0 => 'two-col-columns-11', - 1 => 'two-col-columns-12', - 2 => 'two-col-columns-21', - ], - ], - 'map' => [ - 'pi_flexform/row_class' => 'frame_class', - ] - ], -]; -*/ -class GridelementsToContainerService -{ - private const TABLE_NAME = 'tt_content'; - - protected array $resolveContainer = []; - - protected int $colPosOffset = 0; - - protected array $configuration = []; - - public function __construct( - protected ConnectionPool $connectionPool, - protected DataHandler $dataHandler, - protected FlexFormService $flexFormService, - ) { - $config = & $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']; - $this->resolveContainer = $config['migrationResolveContainer'] ?? []; - $this->colPosOffset = $config['migrationColPosOffset'] ?? 0; - $this->configuration = $config['migrationMapping'] ?? []; - } - - public function migrate(): void - { - $this->initializeDataHandler(); - - // Move children out of container and remove container - foreach ($this->resolveContainer as $containerId) { - $this->resolveContainers((string)$containerId); - } - - $this->migrateConfiguredContainer(); - } - - protected function initializeDataHandler(): void - { - $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class); - $backendUser->user = [ - 'uid' => 0, - 'admin' => 1, - ]; - $this->dataHandler->start([], [], $backendUser); - } - - protected function resolveContainers(string $layout): void - { - $containers = $this->getGridElementsByLayout($layout); - foreach ($containers as $container) { - $this->processContainerResolve($container); - } - } - - protected function processContainerResolve(array $container): void - { - $children = $this->getGridContainerChildren($container['uid']); - // move first child after container - $moveAfterThis = $container; - foreach ($children as $child) { - [$moveAfterThis, $container] = $this->processContainerResolveChild($child, $moveAfterThis, $container); - } - - $this->deleteElement($container['uid']); - } - - protected function processContainerResolveChild(array $child, array $moveAfterThis, array $container): array - { - $this->updateElement( - $child['uid'], - [ - 'tx_gridelements_container' => 0, - 'colPos' => $container['colPos'], - 'header' => $child['header'] ?: $container['header'], - ] - ); - $this->moveElementAfterElement($child['uid'], $moveAfterThis['uid']); - // use this child to move the next child after - $moveAfterThis = $child; - // empty container header so only the first child gets the header - $container['header'] = ''; - - return [$moveAfterThis, $container]; - } - - protected function deleteElement(int $uid): void - { - $this->connectionPool - ->getConnectionForTable(self::TABLE_NAME) - ->update(self::TABLE_NAME, ['delete' => 1], ['uid' => $uid]); - } - - protected function moveElementAfterElement(int $elementToMove, int $elementToMoveAfter): void - { - $this->dataHandler->moveRecord(self::TABLE_NAME, $elementToMove, $elementToMoveAfter * -1); - } - - protected function migrateConfiguredContainer(): void - { - array_walk($this->configuration, function ($config, $key) { - $containers = $this->getGridElementsByLayout((string)$key); - foreach ($containers as $container) { - $container['pi_flexform'] = $this->flexFormService->convertFlexFormContentToArray( - $container['pi_flexform'] - ); - $this->processContainerMigration($container, $config); - } - }); - } - - protected function processContainerMigration(array $container, array $config): void - { - $children = $this->getGridContainerChildren($container['uid']); - foreach ($children as $child) { - $this->processContainerMigrationChild($child, $container); - } - - $data = [ - 'CType' => $this->getCType($container, $config), - 'tx_gridelements_backend_layout' => '', - ]; - - if (isset($config['map']) && is_array($config['map']) && !empty($container['pi_flexform'])) { - $data = $this->addMappedValues($data, $container, $config['map']); - } - - $this->updateElement($container['uid'], $data); - } - - protected function processContainerMigrationChild(array $child, array $container): void - { - $this->updateElement( - $child['uid'], - [ - 'hidden' => $child['hidden'] ?: $container['hidden'], - 'colPos' => $child['tx_gridelements_columns'] + $this->colPosOffset, - 'tx_container_parent' => $child['tx_gridelements_container'], - 'tx_gridelements_columns' => 0, - 'tx_gridelements_container' => 0, - ] - ); - } - - protected function getCType(array $container, array $config): string - { - if (is_array($config['CType'])) { - $value = ArrayUtility::getValueByPath($container, $config['CType']['search']); - $result = $config['CType']['matches'][$value] ?? null; - } else { - $result = $config['CType'] ?? null; - } - - if (empty($result)) { - throw new \Exception('CType must always be set'); - } - - return $result; - } - - protected function addMappedValues(array $data, array $container, array $config): array - { - foreach ($config as $from => $to) { - try { - $value = ArrayUtility::getValueByPath($container, $from); - if (empty($container[$to]) && !empty($value)) { - $data[$to] = $value; - } - } catch (\throwable) { - } - } - - return $data; - } - - protected function updateElement(int $uid, array $changes): void - { - $this->connectionPool - ->getConnectionForTable(self::TABLE_NAME) - ->update(self::TABLE_NAME, $changes, ['uid' => $uid]); - } - - protected function getGridContainerChildren(int $containerUid): array - { - $queryBuilder = $this->getQueryBuilderForTable(); - - return $queryBuilder - ->select('*') - ->where( - $queryBuilder->expr()->eq( - 'tx_gridelements_container', - $queryBuilder->createNamedParameter($containerUid, ParameterType::INTEGER) - ) - ) - ->orderBy('sorting') - ->executeQuery() - ->fetchAllAssociative(); - } - - protected function getGridElementsByLayout(string $layout): array - { - $queryBuilder = $this->getQueryBuilderForTable(); - $expr = $queryBuilder->expr(); - - return $queryBuilder - ->select('*') - ->where( - $expr->eq('CType', $queryBuilder->createNamedParameter('gridelements_pi1')), - $expr->eq('tx_gridelements_backend_layout', $queryBuilder->createNamedParameter($layout)) - ) - ->orderBy('sorting') - ->executeQuery() - ->fetchAllAssociative(); - } - - protected function getQueryBuilderForTable(string $table = 'tt_content'): QueryBuilder - { - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable($table); - - $queryBuilder->getRestrictions() - ->removeByType(HiddenRestriction::class) - ->removeByType(StartTimeRestriction::class) - ->removeByType(EndTimeRestriction::class); - - $queryBuilder->from($table); - - return $queryBuilder; - } -} diff --git a/Classes/Xclass/SiteDatabaseEditRow.php b/Classes/Xclass/SiteDatabaseEditRow.php deleted file mode 100755 index 5e2ca2f..0000000 --- a/Classes/Xclass/SiteDatabaseEditRow.php +++ /dev/null @@ -1,80 +0,0 @@ -siteConfiguration); - } - - /** - * First level of ['customData']['siteData'] to ['databaseRow'] - * - * @throws \RuntimeException - */ - public function addData(array $result): array - { - if ($result['command'] !== 'edit' || !empty($result['databaseRow'])) { - return $result; - } - - $tableName = $result['tableName']; - $siteFinder = GeneralUtility::makeInstance(SiteFinder::class, $this->siteConfiguration); - if ($tableName === 'site') { - $rootPageId = (int)$result['vanillaUid']; - $rowData = $this->getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId); - $result['databaseRow']['uid'] = $rowData['rootPageId']; - $result['databaseRow']['identifier'] = $result['customData']['siteIdentifier']; - } elseif ( - in_array( - $tableName, - ['site_errorhandling', 'site_language', 'site_route', 'site_base_variant'], - true - ) - ) { - $rootPageId = (int)($result['inlineTopMostParentUid'] ?? $result['inlineParentUid']); - try { - $rowData = $this->getRawConfigurationForSiteWithRootPageId($siteFinder, $rootPageId); - $parentFieldName = $result['inlineParentFieldName']; - if (!isset($rowData[$parentFieldName])) { - throw new \RuntimeException('Field "' . $parentFieldName . '" not found', 1520886092); - } - $rowData = $rowData[$parentFieldName][$result['vanillaUid']]; - $result['databaseRow']['uid'] = $result['vanillaUid']; - } catch (SiteNotFoundException) { - $rowData = []; - } - } else { - return $result; - } - - foreach ($rowData as $fieldName => $value) { - // Flat values only - databaseRow has no "tree" - if (!is_array($value)) { - $result['databaseRow'][$fieldName] = $value; - } - } - // All "records" are always on pid 0 - $result['databaseRow']['pid'] = 0; - return $result; - } -} diff --git a/Classes/Xclass/SiteTcaInline.php b/Classes/Xclass/SiteTcaInline.php deleted file mode 100755 index e420715..0000000 --- a/Classes/Xclass/SiteTcaInline.php +++ /dev/null @@ -1,46 +0,0 @@ -addInlineFirstPid($result); - foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) { - if (!$this->isInlineField($fieldConfig)) { - continue; - } - $childTableName = $fieldConfig['config']['foreign_table'] ?? ''; - if (!in_array($childTableName, ['site_errorhandling', 'site_route', 'site_base_variant'], true)) { - return $result; - } - $result['processedTca']['columns'][$fieldName]['children'] = []; - $result = $this->resolveSiteRelatedChildren($result, $fieldName); - if (!empty($result['processedTca']['columns'][$fieldName]['config']['selectorOrUniqueConfiguration'])) { - throw new \RuntimeException( - 'selectorOrUniqueConfiguration not implemented in sites module', - 1624313533 - ); - } - } - - return $result; - } -} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index b684568..87caa87 100755 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -16,21 +16,3 @@ services: Evoweb\EwBase\ToolbarItems\ReleaseToolbarItem: tags: ['backend.toolbar.item'] - - Evoweb\EwBase\Hooks\UsercentricsPostRenderHook: - public: true - - Evoweb\EwBase\Updates\GridelementsToContainerMigration: - public: true - - Evoweb\EwBase\Updates\GridelementsToContainerService: - public: true - - Evoweb\EwBase\Updates\ParentChildToContainerMigration: - public: true - - Evoweb\EwBase\Updates\ParentChildToContainerService: - public: true - - Evoweb\EwBase\Form\FormDataProvider\UsercentricsDatabaseEditRow: - public: true diff --git a/Configuration/SiteConfiguration/Overrides/sites.php b/Configuration/SiteConfiguration/Overrides/sites.php deleted file mode 100755 index 3ec61c2..0000000 --- a/Configuration/SiteConfiguration/Overrides/sites.php +++ /dev/null @@ -1,22 +0,0 @@ - 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site.usercentrics', - 'description' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site.usercentrics.description', - 'config' => [ - 'type' => 'inline', - 'foreign_table' => 'site_usercentrics', - 'maxitems' => 1, - 'appearance' => [ - 'enabledControls' => [ - 'info' => false, - ], - ], - ], -]; - -$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] = str_replace( - ' routes', - ' routes, usercentrics,', - $GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] -); diff --git a/Configuration/SiteConfiguration/site_usercentrics.php b/Configuration/SiteConfiguration/site_usercentrics.php deleted file mode 100755 index d5fd966..0000000 --- a/Configuration/SiteConfiguration/site_usercentrics.php +++ /dev/null @@ -1,78 +0,0 @@ - [ - 'label' => 'id', - 'title' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site_usercentrics.ctrl.title', - 'typeicon_classes' => [ - 'default' => 'ew-usercentrics', - ], - ], - 'columns' => [ - 'id' => [ - 'label' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site_usercentrics.column.id', - 'config' => [ - 'type' => 'input', - 'size' => 12, - 'max' => 12, - ], - ], - 'version' => [ - 'label' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site_usercentrics.column.version', - 'config' => [ - 'type' => 'select', - 'renderType' => 'selectSingle', - 'minitems' => 0, - 'maxitems' => 1, - 'size' => 1, - 'items' => [ - [ - 0 => 'CMP 2', - 1 => 'loader', - ], - [ - 0 => 'CMP 1', - 1 => 'main', - ], - ], - ], - ], - 'applicationContext' => [ - 'label' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site_usercentrics.column.applicationContext', - 'description' => 'Values are separated by line breaks', - 'config' => [ - 'type' => 'text', - 'eval' => 'trim', - ], - ], - 'useBlocker' => [ - 'label' => 'LLL:EXT:ew_base/Resources/Private/Language/locallang_siteconfiguration.xlf:site_usercentrics.column.useBlocker', - 'config' => [ - 'type' => 'check', - 'renderType' => 'checkboxToggle', - 'default' => false, - 'items' => [ - [ - 0 => '', - 1 => true, - ], - ], - ], - ], - ], - 'types' => [ - '1' => [ - 'showitem' => ' - --palette--;;usercentrics, - ', - ], - ], - 'palettes' => [ - 'usercentrics' => [ - 'showitem' => ' - id, version, --linebreak--, - applicationContext, useBlocker, - ', - ], - ], -]; diff --git a/ext_localconf.php b/ext_localconf.php index d6875da..90c27cd 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,45 +3,13 @@ defined('TYPO3') or die('access denied'); use Evoweb\EwBase\Form\Element\PickColorFromImage; -use Evoweb\EwBase\Form\FormDataProvider\UsercentricsDatabaseEditRow; -use Evoweb\EwBase\Form\FormDataProvider\UsercentricsTcaInline; -use Evoweb\EwBase\Hooks\UsercentricsPostRenderHook; -use Evoweb\EwBase\Xclass\SiteDatabaseEditRow; -use Evoweb\EwBase\Xclass\SiteTcaInline; -use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow; -use TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow as BaseSiteDatabaseEditRow; -use TYPO3\CMS\Backend\Form\FormDataProvider\SiteTcaInline as BaseSiteTcaInline; -use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSiteLanguage; -call_user_func(function () { +(static function () { $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['ewb'] = [ 'Evoweb\\EwBase\\ViewHelpers' ]; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'][] = - UsercentricsPostRenderHook::class . '->executePostRenderHook'; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1681197508] = [ 'nodeName' => 'pick-color-from-image', 'priority' => '70', 'class' => PickColorFromImage::class, ]; - - $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][BaseSiteDatabaseEditRow::class] = [ - 'className' => SiteDatabaseEditRow::class, - ]; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][BaseSiteTcaInline::class] = [ - 'className' => SiteTcaInline::class, - ]; - - $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['siteConfiguration'][ - UsercentricsDatabaseEditRow::class - ] = [ - 'depends' => [ BaseSiteDatabaseEditRow::class ], - 'before' => [ DatabaseParentPageRow::class ], - ]; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['siteConfiguration'][ - UsercentricsTcaInline::class - ] = [ - 'depends' => [ BaseSiteTcaInline::class ], - 'before' => [ TcaSiteLanguage::class ], - ]; -}); +})();