diff --git a/Classes/EventListener/ModifyPageLayoutContentEventListener.php b/Classes/EventListener/ModifyPageLayoutContentEventListener.php new file mode 100644 index 0000000..5ee413f --- /dev/null +++ b/Classes/EventListener/ModifyPageLayoutContentEventListener.php @@ -0,0 +1,20 @@ +pageRenderer->loadJavaScriptModule('@b13/collapse/PageModuleCollapse.js'); + } +} 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..421f338 --- /dev/null +++ b/Classes/ViewHelpers/CollapseViewHelper.php @@ -0,0 +1,74 @@ +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..868d4f2 --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,10 @@ + ['core', 'backend'], + 'imports' => [ + '@b13/collapse/' => 'EXT:collapse/Resources/Public/JavaScript/', + ], +]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index ae726ff..89c5ced 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -5,7 +5,8 @@ services: public: false B13\Collapse\: resource: '../Classes/*' - exclude: '../Classes/Domain/Model/*' - 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/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/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html new file mode 100644 index 0000000..c100781 --- /dev/null +++ b/Resources/Private/TemplateOverrides/Partials/PageLayout/RecordDefault/Header.html @@ -0,0 +1,57 @@ + + +
+
+ {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 b5b31cd..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-icons-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 05142f9..b51d6ca 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": "^12.4 || ^13.4" }, "autoload": { "psr-4": { diff --git a/ext_emconf.php b/ext_emconf.php index 38cfb37..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.', @@ -8,10 +10,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-13.99.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php index fe3b597..7d48b9a 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,10 @@ addJavaScript'; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks']['collapse'] = \B13\Collapse\PageModuleModifier::class . '->addCollapseButton'; +if (!is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets'] ?? null)) { + $GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets'] = []; +} +$GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets']['b13/collapse'] = 'EXT:collapse/Resources/Public/Css/'; diff --git a/ext_tables.php b/ext_tables.php deleted file mode 100644 index 30c8d68..0000000 --- a/ext_tables.php +++ /dev/null @@ -1,5 +0,0 @@ -