From 56991c77a746f76ca7af260c89c6c0e51c5dd2f5 Mon Sep 17 00:00:00 2001 From: mhofmann Date: Wed, 30 Aug 2023 14:38:49 +0200 Subject: [PATCH] [TASK] Update for TYPO3 v11 --- .../TableConfigurationPostProcessing.php | 13 +- Classes/Listener/PageTsConfig.php | 14 +- Classes/Tca/Registry.php | 42 +- Classes/Tca/SceConfiguration.php | 169 ++-- Configuration/Services.yaml | 10 +- README.md | 6 +- Resources/Private/Language/locallang.xlf | 22 +- Resources/Public/Icons/Extension.svg | 948 +++++++++--------- composer.json | 17 +- ext_emconf.php | 7 +- ext_localconf.php | 18 +- 11 files changed, 594 insertions(+), 672 deletions(-) diff --git a/Classes/Hooks/TableConfigurationPostProcessing.php b/Classes/Hooks/TableConfigurationPostProcessing.php index b56d528..fe6aca0 100644 --- a/Classes/Hooks/TableConfigurationPostProcessing.php +++ b/Classes/Hooks/TableConfigurationPostProcessing.php @@ -18,22 +18,15 @@ class TableConfigurationPostProcessing implements TableConfigurationPostProcessingHookInterface { + protected Registry $tcaRegistry; - /** - * @var Registry - */ - protected $tcaRegistry; - - /** - * @param Registry|null $tcaRegistry - */ public function __construct(Registry $tcaRegistry = null) { $this->tcaRegistry = $tcaRegistry ?? GeneralUtility::makeInstance(Registry::class); } - public function processData() + public function processData(): void { $this->tcaRegistry->registerIcons(); } -} \ No newline at end of file +} diff --git a/Classes/Listener/PageTsConfig.php b/Classes/Listener/PageTsConfig.php index 87f9b8e..b8e7a10 100644 --- a/Classes/Listener/PageTsConfig.php +++ b/Classes/Listener/PageTsConfig.php @@ -14,22 +14,18 @@ use D3M\Sce\Tca\Registry; use TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent; -use TYPO3\CMS\Core\Utility\GeneralUtility; -class PageTsConfig +final class PageTsConfig { - /** - * @var Registry - */ - protected $tcaRegistry; + protected Registry $tcaRegistry; - public function __construct(Registry $tcaRegistry = null) + public function __construct(Registry $tcaRegistry) { - $this->tcaRegistry = $tcaRegistry ?? GeneralUtility::makeInstance(Registry::class); + $this->tcaRegistry = $tcaRegistry; } public function __invoke(ModifyLoadedPageTsConfigEvent $event): void { $event->addTsConfig($this->tcaRegistry->getPageTsString()); } -} \ No newline at end of file +} diff --git a/Classes/Tca/Registry.php b/Classes/Tca/Registry.php index 24e4b82..b43fb32 100644 --- a/Classes/Tca/Registry.php +++ b/Classes/Tca/Registry.php @@ -12,6 +12,7 @@ * of the License, or any later version. */ +use TYPO3\CMS\Core\Exception; use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider; use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider; use TYPO3\CMS\Core\Imaging\IconRegistry; @@ -19,11 +20,8 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; -class Registry implements SingletonInterface +final class Registry implements SingletonInterface { - /** - * @param SceConfiguration $sceConfiguration - */ public function configureSce(SceConfiguration $sceConfiguration): void { ExtensionManagementUtility::addTcaSelectItem( @@ -33,7 +31,7 @@ public function configureSce(SceConfiguration $sceConfiguration): void $sceConfiguration->getLabel(), $sceConfiguration->getCType(), $sceConfiguration->getCType(), - $sceConfiguration->getGroup() + $sceConfiguration->getGroup(), ] ); @@ -42,7 +40,7 @@ public function configureSce(SceConfiguration $sceConfiguration): void } else { $fieldsArray = []; foreach ($sceConfiguration->getFields() as $fieldName => $fieldConfig) { - $fieldsArray[] = $fieldName . ($fieldConfig['label'] ? ';' . $fieldConfig['label'] : ''); + $fieldsArray[] = $fieldName . (isset($fieldConfig['label']) ? ';' . $fieldConfig['label'] : ''); } $generalTab = implode(',', $fieldsArray); } @@ -86,10 +84,10 @@ public function configureSce(SceConfiguration $sceConfiguration): void $GLOBALS['TCA']['tt_content']['types'][$sceConfiguration->getCType()]['showitem'] = $showitem; $overrides = []; - foreach ($sceConfiguration->getFields() as $fieldName => $fieldConfig) { - if ($fieldConfig['columnOverrides']) { + foreach ($sceConfiguration->getFields() as $fieldName => $fieldConfig) { + if (isset($fieldConfig['columnOverrides'])) { $columnOverrides = $fieldConfig['columnOverrides']; - if ($columnOverrides['allowedFileTypes']) { + if (isset($columnOverrides['allowedFileTypes'])) { $columnOverrides['overrideChildTca']['columns']['uid_local']['config']['appearance']['elementBrowserAllowed'] = $columnOverrides['allowedFileTypes']; } $overrides[$fieldName]['config'] = $columnOverrides; @@ -104,12 +102,12 @@ public function configureSce(SceConfiguration $sceConfiguration): void public function registerIcons(): void { - if (is_array($GLOBALS['TCA']['tt_content']['sceConfiguration'])) { + if (isset($GLOBALS['TCA']['tt_content']['sceConfiguration'])) { $iconRegistry = GeneralUtility::makeInstance(IconRegistry::class); foreach ($GLOBALS['TCA']['tt_content']['sceConfiguration'] as $sceConfiguration) { if (file_exists(GeneralUtility::getFileAbsFileName($sceConfiguration['icon']))) { $provider = BitmapIconProvider::class; - if (strpos($sceConfiguration['icon'], '.svg') !== false) { + if (str_ends_with($sceConfiguration['icon'], '.svg')) { $provider = SvgIconProvider::class; } $iconRegistry->registerIcon( @@ -125,7 +123,7 @@ public function registerIcons(): void $existingIconConfiguration['provider'], $existingIconConfiguration['options'] ); - } catch (\TYPO3\CMS\Core\Exception $e) { + } catch (Exception $_) { } } } @@ -134,22 +132,7 @@ public function registerIcons(): void /** * Adds TSconfig - * - * @param array $TSdataArray - * @param int $id - * @param array $rootLine - * @param array $returnPartArray - * @return array */ - public function addPageTS($TSdataArray, $id, $rootLine, $returnPartArray): array - { - if (empty($GLOBALS['TCA']['tt_content']['sceConfiguration'])) { - return [$TSdataArray, $id, $rootLine, $returnPartArray]; - } - $TSdataArray['default'] = $this->getPageTsString(); - return [$TSdataArray, $id, $rootLine, $returnPartArray]; - } - public function getPageTsString(): string { if (empty($GLOBALS['TCA']['tt_content']['sceConfiguration'])) { @@ -170,8 +153,9 @@ public function getPageTsString(): string } } + $pageTs = ''; foreach ($groupedByGroup as $group => $sceConfigurations) { - $groupLabel = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['itemGroups'][$group] ? $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['itemGroups'][$group] : $group; + $groupLabel = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['itemGroups'][$group] ?: $group; $content = ' mod.wizards.newContentElement.wizardItems.' . $group . '.header = ' . $groupLabel . ' @@ -195,4 +179,4 @@ public function getPageTsString(): string return $pageTs; } -} \ No newline at end of file +} diff --git a/Classes/Tca/SceConfiguration.php b/Classes/Tca/SceConfiguration.php index 2f815dc..2fabdc6 100644 --- a/Classes/Tca/SceConfiguration.php +++ b/Classes/Tca/SceConfiguration.php @@ -12,63 +12,39 @@ * of the License, or any later version. */ -class SceConfiguration +final class SceConfiguration { - /** - * @var string - */ - protected $cType = ''; + protected string $cType = ''; - /** - * @var string - */ - protected $label = ''; + protected string $label = ''; - /** - * @var string - */ - protected $description = ''; + protected string $description = ''; /** - * @var mixed[] + * @var array */ - protected $fields = []; + protected array $fields = []; /** - * @var mixed[] + * @var array */ - protected $palettes = []; + protected array $palettes = []; - /** - * @var string - */ - protected $additionalTabs = 'none'; + protected string $additionalTabs = 'none'; - /** - * @var string - */ - protected $showitem = ''; + protected string $showitem = ''; - /** - * @var string - */ - protected $icon = 'EXT:sce/Resources/Public/Icons/Extension.svg'; + protected string $icon = 'EXT:sce/Resources/Public/Icons/Extension.svg'; - /** - * @var bool - */ - protected $saveAndCloseInNewContentElementWizard = false; + protected bool $saveAndCloseInNewContentElementWizard = false; - /** - * @var bool - */ - protected $registerInNewContentElementWizard = true; + protected bool $registerInNewContentElementWizard = true; + + protected string $group = 'sce'; /** - * @var string + * @param array> $fields */ - protected $group = 'sce'; - public function __construct( string $cType, string $label, @@ -81,94 +57,36 @@ public function __construct( $this->fields = $fields; } - /** - * @param mixed[] $palettes - * @return SceConfiguration - */ - public function setPalettes(array $palettes): SceConfiguration - { - $this->palettes = $palettes; - return $this; - } - - /** - * @param string $icon - * @return SceConfiguration - */ public function setIcon(string $icon): SceConfiguration { $this->icon = $icon; return $this; } - /** - * @param string $additionalTabs - * @return SceConfiguration - */ - public function setAdditionalTabs(string $additionalTabs): SceConfiguration - { - $this->additionalTabs = $additionalTabs; - return $this; - } - - /** - * @param string $showitem - * @return SceConfiguration - */ - public function setShowitem(string $showitem): SceConfiguration - { - $this->showitem = $showitem; - return $this; - } - - /** - * @param bool $saveAndCloseInNewContentElementWizard - * @return SceConfiguration - */ public function setSaveAndCloseInNewContentElementWizard(bool $saveAndCloseInNewContentElementWizard): SceConfiguration { $this->saveAndCloseInNewContentElementWizard = $saveAndCloseInNewContentElementWizard; return $this; } - /** - * @param bool $registerInNewContentElementWizard - * @return SceConfiguration - */ public function setRegisterInNewContentElementWizard(bool $registerInNewContentElementWizard): SceConfiguration { $this->registerInNewContentElementWizard = $registerInNewContentElementWizard; return $this; } - /** - * @param string $group - * @return SceConfiguration - */ - public function setGroup(string $group): SceConfiguration - { - $this->group = $group; - return $this; - } - - /** - * @return string - */ public function getCType(): string { return $this->cType; } - /** - * @return string - */ public function getLabel(): string { return $this->label; } /** - * @return mixed[] + * @return array */ public function getFields(): array { @@ -176,7 +94,7 @@ public function getFields(): array } /** - * @return mixed[] + * @return array */ public function getPalettes(): array { @@ -184,31 +102,49 @@ public function getPalettes(): array } /** - * @return string + * @param array $palettes */ + public function setPalettes(array $palettes): SceConfiguration + { + $this->palettes = $palettes; + return $this; + } + public function getAdditionalTabs(): string { return $this->additionalTabs; } - /** - * @return string - */ + public function setAdditionalTabs(string $additionalTabs): SceConfiguration + { + $this->additionalTabs = $additionalTabs; + return $this; + } + public function getShowitem(): string { return $this->showitem; } - /** - * @return string - */ + public function setShowitem(string $showitem): SceConfiguration + { + $this->showitem = $showitem; + return $this; + } + public function getGroup(): string { return $this->group; } + public function setGroup(string $group): SceConfiguration + { + $this->group = $group; + return $this; + } + /** - * @return mixed[] + * @return array */ public function toArray(): array { @@ -222,7 +158,20 @@ public function toArray(): array 'registerInNewContentElementWizard' => $this->registerInNewContentElementWizard, 'additionalTabs' => $this->additionalTabs, 'showitem' => $this->showitem, - 'group' => $this->group + 'group' => $this->group, ]; } -} \ No newline at end of file + + /** + * @param array> $fields + */ + public static function showItemGenerator(array $fields, string ...$showItems): string + { + $fieldKeys = array_keys($fields); + $showItem = implode(',', $showItems); + return sprintf( + $showItem, + implode(',', $fieldKeys) + ); + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 205d36e..968e21a 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -1,6 +1,14 @@ services: + _defaults: + autowire: true + autoconfigure: true + public: false + + D3M\Sce\: + resource: '../Classes/*' + D3M\Sce\Listener\PageTsConfig: tags: - name: event.listener identifier: 'tx-sce-page-ts-config' - event: TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent \ No newline at end of file + event: TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent diff --git a/README.md b/README.md index d46e46e..c06f55d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # EXT:sce - A TYPO3 extension for creating simple content elements -Webpages ca be seen as a composition of 3 elements: grids building the structure (sections or columns), containers like a card container containing several cards and very often quite simple content elements (like text elements with header and text). Some of these content elements may have the same fields, but they 'behave' differently in different contexts e.g. a text element can be a rendered as 'normal' text or as a card in a card container. +Webpages ca be seen as a composition of 3 elements: grids building the structure (sections or columns), containers like a card container containing several cards and very often quite simple content elements (like text elements with header and text). Some of these content elements may have the same fields, but they 'behave' differently in different contexts e.g. a text element can be a rendered as 'normal' text or as a card in a card container. The idea of this extension is to have a simple way to build content elements from scratch, which are easy to configure by integrators easy to use by editors. Instead of using several layout options in the content element itself to make it fit a certain context, the suggestion of this extension is, to build as many content elements as there are contexts in your webpage. By using mainly default fields of the tt_content table, the content type can be easily switched in bulk from TYPO3-default content type to site-package-specific content type and vice versa in the database. @@ -101,5 +101,5 @@ To find out, which variables are available, you can add `{_all} - - - - Simple Content Elements - - - Context - - - - \ No newline at end of file + + + + Simple Content Elements + + + Context + + + + diff --git a/Resources/Public/Icons/Extension.svg b/Resources/Public/Icons/Extension.svg index 234523e..0bd5737 100755 --- a/Resources/Public/Icons/Extension.svg +++ b/Resources/Public/Icons/Extension.svg @@ -1,474 +1,474 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 91c10ec..3dd5ecb 100644 --- a/composer.json +++ b/composer.json @@ -5,19 +5,16 @@ "license": "GPL-2.0-or-later", "require": { "typo3/cms-backend": "^9.5 || ^10.4 || ^11.5", - "typo3/cms-fluid-styled-content": "^9.5 || ^11.5" + "typo3/cms-fluid-styled-content": "^9.5 || ^10.4 || ^11.5" }, - "autoload": { - "psr-4": { - "D3M\\Sce\\": "Classes/" - } - }, - "replace": { - "typo3-ter/sce": "self.version" - }, "extra": { "typo3/cms": { "extension-key": "sce" } - } + }, + "autoload": { + "psr-4": { + "D3M\\Sce\\": "Classes" + } + } } diff --git a/ext_emconf.php b/ext_emconf.php index 9d81a42..dbc6ccb 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,11 +10,10 @@ 'state' => 'stable', 'uploadfolder' => false, 'createDirs' => '', - 'clearCacheOnLoad' => true, 'version' => '1.0.0', 'constraints' => [ 'depends' => ['typo3' => '9.5.0-11.5.99'], 'conflicts' => [], - 'suggests' => [] - ] -]; \ No newline at end of file + 'suggests' => [], + ], +]; diff --git a/ext_localconf.php b/ext_localconf.php index 686f45d..d7fcaf4 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,18 +3,14 @@ defined('TYPO3_MODE') || die('Access denied.'); call_user_func(static function () { - $typo3Version = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class); - if ($typo3Version->getMajorVersion() === 9) { - // Else PageTsConfig Listener is used for ModifyLoadedPageTsConfigEvent - \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class)->connect( - \TYPO3\CMS\Backend\Utility\BackendUtility::class, - 'getPagesTSconfigPreInclude', - D3M\Sce\Tca\Registry::class, - 'addPageTS' - ); - } + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class)->connect( + \TYPO3\CMS\Backend\Utility\BackendUtility::class, + 'getPagesTSconfigPreInclude', + D3M\Sce\Tca\Registry::class, + 'addPageTS' + ); // Register icons $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing']['tx_sce'] = \D3M\Sce\Hooks\TableConfigurationPostProcessing::class; -}); \ No newline at end of file +});