diff --git a/Classes/EventListener/ModifyPageLayoutContentEventListener.php b/Classes/EventListener/ModifyPageLayoutContentEventListener.php new file mode 100644 index 0000000..a9147fa --- /dev/null +++ b/Classes/EventListener/ModifyPageLayoutContentEventListener.php @@ -0,0 +1,16 @@ +loadRequireJsModule('TYPO3/CMS/Collapse/PageModuleCollapse'); + } +} \ No newline at end of file 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/Collapse/CollapsibleViewHelper.php b/Classes/ViewHelpers/Collapse/CollapsibleViewHelper.php new file mode 100644 index 0000000..db18508 --- /dev/null +++ b/Classes/ViewHelpers/Collapse/CollapsibleViewHelper.php @@ -0,0 +1,26 @@ +uc['B13']['Collapse'] ?? ''; + $collapsedItems = GeneralUtility::trimExplode(',', $result); + + return array_filter($collapsedItems); + } +} diff --git a/Classes/ViewHelpers/Collapse/ColumnViewHelper.php b/Classes/ViewHelpers/Collapse/ColumnViewHelper.php new file mode 100644 index 0000000..4f80c81 --- /dev/null +++ b/Classes/ViewHelpers/Collapse/ColumnViewHelper.php @@ -0,0 +1,54 @@ +registerArgument('page', 'array', 'Page record array', true); + $this->registerArgument('column', GridColumn::class, '', true); + } + + public function render(): string + { + $page = $this->arguments['page']; + /** @var GridColumn $column */ + $column = $this->arguments['column']; + + $iconFactory = GeneralUtility::makeInstance(IconFactory::class); + + if ($column instanceof GridColumn) { + $identifier = sprintf('column_%s_%s', $column->getColumnNumber(), $page['uid']); + $isCollapsed = in_array($identifier, $this->getCollapsedItems(), true); + + return ''; + } + + return ''; + } + +} diff --git a/Classes/ViewHelpers/Collapse/ContentViewHelper.php b/Classes/ViewHelpers/Collapse/ContentViewHelper.php new file mode 100644 index 0000000..c8119ae --- /dev/null +++ b/Classes/ViewHelpers/Collapse/ContentViewHelper.php @@ -0,0 +1,78 @@ +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 = $row['uid']; + $identifier = 'tt_content_' . $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($identifier, $this->getCollapsedItems(), true); + + return ''; + } + + return ''; + } + + public function getCollapsedItems(): array + { + $collapsedItems = parent::getCollapsedItems(); + return array_map(fn(int|string $item) => str_starts_with((string) $item, 'tt_content_') ? (string) $item : 'tt_content_' . $item, $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..10958cc --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,8 @@ + ['backend'], + 'imports' => [ + 'b13/collapse' => 'EXT:collapse/Resources/Public/JavaScript/', + ], +]; \ No newline at end of file diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index ae726ff..148f409 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' \ No newline at end of file diff --git a/Configuration/page.tsconfig b/Configuration/page.tsconfig new file mode 100644 index 0000000..3d7dcad --- /dev/null +++ b/Configuration/page.tsconfig @@ -0,0 +1,3 @@ +templates.typo3/cms-backend { + 1691683586 = b13/collapse:Resources/Private/TemplateOverrides +} \ No newline at end of file diff --git a/Resources/Private/TemplateOverrides/Partials/PageLayout/Grid/ColumnHeader.html b/Resources/Private/TemplateOverrides/Partials/PageLayout/Grid/ColumnHeader.html new file mode 100644 index 0000000..44f5a57 --- /dev/null +++ b/Resources/Private/TemplateOverrides/Partials/PageLayout/Grid/ColumnHeader.html @@ -0,0 +1,44 @@ + + +