From eee9811bde53521dbdb53aaeaa03b6973ae5e0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B6ffler?= Date: Wed, 19 Jul 2023 16:09:13 +0200 Subject: [PATCH 1/3] Update composer.json Add v12 support in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 05142f9..0357e7f 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "GPL-2.0-or-later" ], "require": { - "typo3/cms-backend": "^11.5" + "typo3/cms-backend": "^11.5 || ^12.4" }, "autoload": { "psr-4": { From c9ebe7dec9ea96039d76d4e8aaece71046eda994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B6ffler?= Date: Fri, 11 Aug 2023 09:06:47 +0200 Subject: [PATCH 2/3] [FEATURE] Set to v12 support only --- .../ModifyPageLayoutContentEventListener.php | 16 ++++ Classes/PageModuleModifier.php | 77 ------------------- Classes/ViewHelpers/CollapseViewHelper.php | 71 +++++++++++++++++ Configuration/JavaScriptModules.php | 8 ++ Configuration/Services.yaml | 5 ++ Configuration/page.tsconfig | 3 + .../PageLayout/RecordDefault/Header.html | 59 ++++++++++++++ Resources/Public/Css/pagemodule.css | 6 +- .../Public/JavaScript/PageModuleCollapse.js | 2 +- composer.json | 2 +- ext_emconf.php | 4 +- ext_localconf.php | 6 -- 12 files changed, 169 insertions(+), 90 deletions(-) create mode 100644 Classes/EventListener/ModifyPageLayoutContentEventListener.php delete mode 100644 Classes/PageModuleModifier.php create mode 100644 Classes/ViewHelpers/CollapseViewHelper.php create mode 100644 Configuration/JavaScriptModules.php create mode 100644 Configuration/page.tsconfig create mode 100644 Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html delete mode 100644 ext_localconf.php diff --git a/Classes/EventListener/ModifyPageLayoutContentEventListener.php b/Classes/EventListener/ModifyPageLayoutContentEventListener.php new file mode 100644 index 0000000..79c0b1d --- /dev/null +++ b/Classes/EventListener/ModifyPageLayoutContentEventListener.php @@ -0,0 +1,16 @@ +loadRequireJsModule('TYPO3/CMS/Collapse/PageModuleCollapse'); + } +} diff --git a/Classes/PageModuleModifier.php b/Classes/PageModuleModifier.php deleted file mode 100644 index f054348..0000000 --- a/Classes/PageModuleModifier.php +++ /dev/null @@ -1,77 +0,0 @@ -pageRenderer = $pageRenderer; - $this->iconFactory = $iconFactory; - } - - public function addCollapseButton(array $parameters, $parentObject): string - { - if ($parentObject instanceof PageLayoutView || $parentObject instanceof GridColumnItem) { - $contentElementId = (int)$parameters[1]; - $row = $parameters[2]; - $recordTitle = BackendUtility::getRecordTitle('tt_content', $row); - $typeLabel = $this->getTypeLabel($row); - $isCollapsed = in_array($contentElementId, $this->getCollapsedItems(), true); - return ''; - } - return ''; - } - - public function addJavaScript(): string - { - $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Collapse/PageModuleCollapse'); - return ''; - } - - public function getCollapsedItems(): array - { - $result = $GLOBALS['BE_USER']->uc['B13']['Collapse'] ?? ''; - $collapsedItems = GeneralUtility::intExplode(',', $result); - return array_filter($collapsedItems); - } - - protected function getTypeLabel(array $row): string - { - $typeValue = BackendUtility::getTCAtypeValue('tt_content', $row); - $label = ''; - foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $itm) { - if ($itm[1] == $typeValue) { - $label = $itm[0]; - break; - } - } - if ($label !== '') { - return $GLOBALS['LANG']->sL($label); - } - return ''; - } -} diff --git a/Classes/ViewHelpers/CollapseViewHelper.php b/Classes/ViewHelpers/CollapseViewHelper.php new file mode 100644 index 0000000..2cab9e8 --- /dev/null +++ b/Classes/ViewHelpers/CollapseViewHelper.php @@ -0,0 +1,71 @@ +registerArgument('contentElementId', 'int', 'Content Element UID', true); + $this->registerArgument('row', 'array', 'Content record array', true); + $this->registerArgument('type', AbstractGridObject::class, '', true); + } + + public function render(): string + { + $type = $this->arguments['type']; + $row = $this->arguments['row']; + $contentElementId = $this->arguments['contentElementId']; + + $iconFactory = GeneralUtility::makeInstance(IconFactory::class); + + if ($type instanceof GridColumnItem && !$type instanceof ContainerGridColumnItem) { + $recordTitle = BackendUtility::getRecordTitle('tt_content', $row); + $typeLabel = $this->getTypeLabel($row); + $isCollapsed = in_array($contentElementId, $this->getCollapsedItems(), true); + + return ''; + } + + return ''; + } + + public function getCollapsedItems(): array + { + $result = $GLOBALS['BE_USER']->uc['B13']['Collapse'] ?? ''; + $collapsedItems = GeneralUtility::intExplode(',', $result); + + return array_filter($collapsedItems); + } + + protected function getTypeLabel(array $row): string + { + $typeValue = BackendUtility::getTCAtypeValue('tt_content', $row); + $label = ''; + foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $itm) { + if ($itm['value'] == $typeValue) { + $label = $itm['label']; + break; + } + } + if ($label !== '') { + return $GLOBALS['LANG']->sL($label); + } + + return ''; + } +} diff --git a/Configuration/JavaScriptModules.php b/Configuration/JavaScriptModules.php new file mode 100644 index 0000000..4f6b39b --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,8 @@ + ['backend'], + 'imports' => [ + 'b13/collapse' => 'EXT:collapse/Resources/Public/JavaScript/', + ], +]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index ae726ff..03f42d3 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -9,3 +9,8 @@ services: B13\Collapse\PageModuleModifier: public: true + + B13\Collapse\EventListener\ModifyPageLayoutContentEventListener: + tags: + - name: event.listener + identifier: 'paste-reference/backend/modify-page-layout-content' diff --git a/Configuration/page.tsconfig b/Configuration/page.tsconfig new file mode 100644 index 0000000..3979b0e --- /dev/null +++ b/Configuration/page.tsconfig @@ -0,0 +1,3 @@ +templates.typo3/cms-backend { + 1691683586 = b13/collapse:Resources/Private/TemplateOverrides +} diff --git a/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html new file mode 100644 index 0000000..097e099 --- /dev/null +++ b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html @@ -0,0 +1,59 @@ + + +
+
+ {item.icons -> f:format.raw()} + + + + + +
+
+ {item.contentTypeLabel} +
+
+ +
+
+ + + + + + + + + + + + + + +
+ + + +
+
+
+
diff --git a/Resources/Public/Css/pagemodule.css b/Resources/Public/Css/pagemodule.css index 8300a98..8b32f03 100644 --- a/Resources/Public/Css/pagemodule.css +++ b/Resources/Public/Css/pagemodule.css @@ -1,10 +1,10 @@ -.t3-page-ce-header-icons-left button[data-b13-collapse] { +.t3-page-ce-header-left button[data-b13-collapse] { display: none; } -.t3-page-ce-header-icons-right button[data-b13-collapse][aria-expanded=false] > span:first-child { +.t3-page-ce-header-right button[data-b13-collapse][aria-expanded=false] > span:first-child { display: none; } -.t3-page-ce-header-icons-right button[data-b13-collapse][aria-expanded=true] > span:last-child { +.t3-page-ce-header-right button[data-b13-collapse][aria-expanded=true] > span:last-child { display: none; } diff --git a/Resources/Public/JavaScript/PageModuleCollapse.js b/Resources/Public/JavaScript/PageModuleCollapse.js index d434cbb..f6653ac 100644 --- a/Resources/Public/JavaScript/PageModuleCollapse.js +++ b/Resources/Public/JavaScript/PageModuleCollapse.js @@ -8,7 +8,7 @@ define([ let selectors = { button: 'button[data-b13-collapse]', toolbarContainer: '.t3-page-ce-header', - rightToolbarContainer: '.t3-page-ce-header-icons-right > .btn-toolbar' + rightToolbarContainer: '.t3-page-ce-header-right > .btn-toolbar' }; DocumentService.ready().then(() => { diff --git a/composer.json b/composer.json index 0357e7f..2583168 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "GPL-2.0-or-later" ], "require": { - "typo3/cms-backend": "^11.5 || ^12.4" + "typo3/cms-backend": "^12.4" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 38cfb37..3a93142 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -8,10 +8,10 @@ 'author' => 'b13 GmbH', 'author_email' => 'typo3@b13.com', 'author_company' => '', - 'version' => '1.0.0', + 'version' => '2.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '11.5.0-11.5.99', + 'typo3' => '12.4.0-12.4.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php deleted file mode 100644 index fe3b597..0000000 --- a/ext_localconf.php +++ /dev/null @@ -1,6 +0,0 @@ -addJavaScript'; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks']['collapse'] = \B13\Collapse\PageModuleModifier::class . '->addCollapseButton'; From 8567230bfeec7f99fd82dc72f536b578e437282e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B6ffler?= Date: Fri, 11 Aug 2023 09:13:25 +0200 Subject: [PATCH 3/3] [TASK] Do not escape ViewHelper output --- Classes/ViewHelpers/CollapseViewHelper.php | 2 ++ .../Partials/PageLayout/RecordDefault/Header.html | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/ViewHelpers/CollapseViewHelper.php b/Classes/ViewHelpers/CollapseViewHelper.php index 2cab9e8..85204d4 100644 --- a/Classes/ViewHelpers/CollapseViewHelper.php +++ b/Classes/ViewHelpers/CollapseViewHelper.php @@ -14,6 +14,8 @@ class CollapseViewHelper extends AbstractViewHelper { + protected $escapeOutput = false; + public function initializeArguments(): void { parent::initializeArguments(); diff --git a/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html index 097e099..c100781 100644 --- a/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html +++ b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html @@ -50,9 +50,7 @@ - - - +