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/4] 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/4] [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/4] [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 @@ - - - + From 009947b982d02ba6d262c2c4ac97ca00281f37d5 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Thu, 26 Jun 2025 12:18:35 +0200 Subject: [PATCH 4/4] !!![TASK] change requirments Support TYPO3 v12 and v13 --- .../ModifyPageLayoutContentEventListener.php | 10 ++++-- Classes/ViewHelpers/CollapseViewHelper.php | 3 +- Configuration/JavaScriptModules.php | 6 ++-- Configuration/Services.yaml | 4 --- README.md | 1 - .../Public/JavaScript/PageModuleCollapse.js | 32 +++++++++---------- composer.json | 2 +- ext_emconf.php | 4 ++- ext_localconf.php | 10 ++++++ ext_tables.php | 5 --- 10 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 ext_localconf.php delete mode 100644 ext_tables.php diff --git a/Classes/EventListener/ModifyPageLayoutContentEventListener.php b/Classes/EventListener/ModifyPageLayoutContentEventListener.php index 79c0b1d..5ee413f 100644 --- a/Classes/EventListener/ModifyPageLayoutContentEventListener.php +++ b/Classes/EventListener/ModifyPageLayoutContentEventListener.php @@ -1,16 +1,20 @@ loadRequireJsModule('TYPO3/CMS/Collapse/PageModuleCollapse'); + $this->pageRenderer->loadJavaScriptModule('@b13/collapse/PageModuleCollapse.js'); } } diff --git a/Classes/ViewHelpers/CollapseViewHelper.php b/Classes/ViewHelpers/CollapseViewHelper.php index 85204d4..421f338 100644 --- a/Classes/ViewHelpers/CollapseViewHelper.php +++ b/Classes/ViewHelpers/CollapseViewHelper.php @@ -1,5 +1,7 @@ ['backend'], + 'dependencies' => ['core', 'backend'], 'imports' => [ - 'b13/collapse' => 'EXT:collapse/Resources/Public/JavaScript/', + '@b13/collapse/' => 'EXT:collapse/Resources/Public/JavaScript/', ], ]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 03f42d3..89c5ced 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -5,10 +5,6 @@ services: public: false B13\Collapse\: resource: '../Classes/*' - exclude: '../Classes/Domain/Model/*' - - B13\Collapse\PageModuleModifier: - public: true B13\Collapse\EventListener\ModifyPageLayoutContentEventListener: tags: diff --git a/README.md b/README.md index f8acf9e..016e117 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ This is our bare minimum feature set, a few features will following along: * Enable / disable collapsing per Content Type * Disable collapsing in User Settings -* Support for TYPO3 v12 * Customizable preview in collapsed state ## Credits diff --git a/Resources/Public/JavaScript/PageModuleCollapse.js b/Resources/Public/JavaScript/PageModuleCollapse.js index 1208903..1676fbc 100644 --- a/Resources/Public/JavaScript/PageModuleCollapse.js +++ b/Resources/Public/JavaScript/PageModuleCollapse.js @@ -1,22 +1,21 @@ -/** - * Detects content elements to enable expand/collapse - */ -define([ - 'TYPO3/CMS/Core/DocumentService', - 'TYPO3/CMS/Backend/Storage/Persistent', -], function (DocumentService, PersistentStorage) { - let selectors = { - button: 'button[data-b13-collapse]', - toolbarContainer: '.t3-page-ce-header', - rightToolbarContainer: '.t3-page-ce-header-right > .btn-toolbar' - }; +import Persistent from '@typo3/backend/storage/persistent.js'; +import DocumentService from '@typo3/core/document-service.js'; DocumentService.ready().then(() => { + let selectors = { + button: 'button[data-b13-collapse]', + toolbarContainer: '.t3-page-ce-header', + rightToolbarContainer: '.t3-page-ce-header-right > .btn-toolbar' + }; document.querySelectorAll(selectors.button).forEach((btn) => { const substituteContent = JSON.parse(btn.dataset.b13Title); // move each element to the right spot first. let toolbar = btn.closest(selectors.toolbarContainer); btn.remove(); + if (document.querySelector(btn.dataset.bsTarget) == null) { + // no element-preview + return; + } toolbar.querySelector(selectors.rightToolbarContainer).append(btn); const substituteNode = document.createElement('div'); substituteNode.innerHTML = '' + substituteContent['title'] + '' + ' ' + substituteContent['type']; @@ -31,15 +30,15 @@ define([ // Add event handles to update BE_USERs->uc when collapse/show is used // The CE is expanded again document.querySelector(btn.dataset.bsTarget).addEventListener('show.bs.collapse', () => { - PersistentStorage.removeFromList('B13.Collapse', btn.dataset.b13Collapse); + Persistent.removeFromList('B13.Collapse', btn.dataset.b13Collapse); substituteNode.classList.add('d-none'); }); // The CE is about to be collapsed document.querySelector(btn.dataset.bsTarget).addEventListener('hide.bs.collapse', () => { - if (PersistentStorage.isset('B13.Collapse') === false) { - PersistentStorage.set('B13.Collapse',''); + if (Persistent.isset('B13.Collapse') === false) { + Persistent.set('B13.Collapse',''); } - PersistentStorage.addToList('B13.Collapse', btn.dataset.b13Collapse); + Persistent.addToList('B13.Collapse', btn.dataset.b13Collapse); substituteNode.classList.remove('d-none'); }); @@ -47,4 +46,3 @@ define([ document.querySelector(btn.dataset.bsTarget).parentNode.prepend(substituteNode); }); }); -}); diff --git a/composer.json b/composer.json index 2583168..b51d6ca 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "GPL-2.0-or-later" ], "require": { - "typo3/cms-backend": "^12.4" + "typo3/cms-backend": "^12.4 || ^13.4" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 3a93142..5dc4bd1 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,5 +1,7 @@ 'Content Element Collapse or Expand View in TYPO3 Page Module', 'description' => 'Collapse large content element previews in TYPO3\'s Page Module.', @@ -11,7 +13,7 @@ 'version' => '2.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '12.4.0-12.4.99', + 'typo3' => '12.4.0-13.99.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php new file mode 100644 index 0000000..7d48b9a --- /dev/null +++ b/ext_localconf.php @@ -0,0 +1,10 @@ +