From 807a66e9b0556d3ae8e328f6d9ec8c6860572c5c Mon Sep 17 00:00:00 2001 From: Nicole Cordes Date: Wed, 25 Jan 2023 20:26:42 +0100 Subject: [PATCH 1/2] [FEATURE] Show remaining maxitems in page module --- .../ViewHelpers/ExtendPartialViewHelper.php | 32 +++++++++++ Classes/ViewHelpers/MaxitemsViewHelper.php | 53 +++++++++++++++++++ Configuration/Services.yaml | 3 ++ Configuration/TCA/Overrides/pages.php | 9 ++++ Configuration/TCA/Overrides/sys_template.php | 9 ++++ Configuration/TSconfig/Page/maxitems.tsconfig | 2 + Configuration/TypoScript/constants.typoscript | 10 ++++ Configuration/TypoScript/setup.typoscript | 2 + .../Backend/PageLayout/Grid/ColumnHeader.html | 27 ++++++++++ .../Partials/Backend/PageLayout/Record.html | 11 ++++ Resources/Public/Css/backend.css | 34 ++++++++++++ 11 files changed, 192 insertions(+) create mode 100644 Classes/ViewHelpers/ExtendPartialViewHelper.php create mode 100644 Classes/ViewHelpers/MaxitemsViewHelper.php create mode 100644 Configuration/TCA/Overrides/pages.php create mode 100644 Configuration/TCA/Overrides/sys_template.php create mode 100644 Configuration/TSconfig/Page/maxitems.tsconfig create mode 100644 Configuration/TypoScript/constants.typoscript create mode 100644 Configuration/TypoScript/setup.typoscript create mode 100644 Resources/Private/Partials/Backend/PageLayout/Grid/ColumnHeader.html create mode 100644 Resources/Private/Partials/Backend/PageLayout/Record.html create mode 100644 Resources/Public/Css/backend.css diff --git a/Classes/ViewHelpers/ExtendPartialViewHelper.php b/Classes/ViewHelpers/ExtendPartialViewHelper.php new file mode 100644 index 0000000..82d469c --- /dev/null +++ b/Classes/ViewHelpers/ExtendPartialViewHelper.php @@ -0,0 +1,32 @@ +getTemplatePaths()->getPartialRootPaths(); + $newPartialPaths = array_filter($partialPaths, function ($path) use ($packagePath) { + return strpos($path, $packagePath) === false; + }); + $renderingContext->getTemplatePaths()->setPartialRootPaths($newPartialPaths); + $content = $renderChildrenClosure(); + $renderingContext->getTemplatePaths()->setPartialRootPaths($partialPaths); + + return $content; + } +} diff --git a/Classes/ViewHelpers/MaxitemsViewHelper.php b/Classes/ViewHelpers/MaxitemsViewHelper.php new file mode 100644 index 0000000..51114f6 --- /dev/null +++ b/Classes/ViewHelpers/MaxitemsViewHelper.php @@ -0,0 +1,53 @@ +registerArgument('column', 'TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn', 'Current column object', true); + } + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + $maxitems = -1; + + /** @var GridColumn $column */ + $column = $arguments['column']; + $pageId = $column->getContext()->getPageId(); + $colPos = $column->getColumnNumber(); + $language = $column->getContext()->getSiteLanguage()->getLanguageId(); + + $identifier = implode('_', [$pageId, $language, $colPos]); + + $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); + if ($viewHelperVariableContainer->exists(self::class, $identifier)) { + return $viewHelperVariableContainer->get(self::class, $identifier); + } + + $backendLayoutConfiguration = BackendLayoutConfiguration::createFromPageId($pageId); + $columnConfiguration = $backendLayoutConfiguration->getConfigurationByColPos($colPos); + + if (!empty($columnConfiguration['maxitems'])) { + $maxitems = $columnConfiguration['maxitems'] - count($column->getItems()); + } + + $viewHelperVariableContainer->add(self::class, $identifier, $maxitems); + + return $maxitems; + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index bbea232..3060320 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -4,6 +4,9 @@ services: autoconfigure: true public: false + IchHabRecht\ContentDefender\: + resource: '../Classes/*' + IchHabRecht\ContentDefender\Hooks\WizardItemsHook: tags: - name: event.listener diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php new file mode 100644 index 0000000..ae69825 --- /dev/null +++ b/Configuration/TCA/Overrides/pages.php @@ -0,0 +1,9 @@ + + + + + + +
+ + + + {maxitems} + + + {maxitems} + + + {maxitems} + + + +
+
+
+ + diff --git a/Resources/Private/Partials/Backend/PageLayout/Record.html b/Resources/Private/Partials/Backend/PageLayout/Record.html new file mode 100644 index 0000000..fb58f21 --- /dev/null +++ b/Resources/Private/Partials/Backend/PageLayout/Record.html @@ -0,0 +1,11 @@ + + + +
+ +
+
+
+ diff --git a/Resources/Public/Css/backend.css b/Resources/Public/Css/backend.css new file mode 100644 index 0000000..f0582c5 --- /dev/null +++ b/Resources/Public/Css/backend.css @@ -0,0 +1,34 @@ +@charset "UTF-8"; + +.t3-cd-badge-container { + position: relative; +} + +.t3-cd-badge-container[data-maxitems="0"] .t3-page-ce .t3js-page-new-ce, +.t3-cd-badge-container[data-maxitems="0"] .t3-page-ce .t3-page-ce-dropzone { + display: none; +} + +.t3-cd-badge { + position: absolute; + left: 0; + top: 0; + transform: translate(-50%, 0); + background-color: #ff0000; + z-index: 100; +} + +.t3-cd-badge.text-bg-success { + background-color: #107c10; + color: #ffffff; +} + +.t3-cd-badge.text-bg-warning { + background-color: #e8a33d; + color: #ffffff; +} + +.t3-cd-badge.text-bg-danger { + background-color: #ff0000; + color: #ffffff; +} From cda2b267e92ac6d02f2f09d6716d4db6c9cbb5c6 Mon Sep 17 00:00:00 2001 From: Nicole Cordes Date: Thu, 26 Jan 2023 14:33:38 +0100 Subject: [PATCH 2/2] [TASK] Add information to README --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index fc9eb0a..8ac6dd3 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,20 @@ columns { } ``` +**Enable maxitems count in page module (*!experimental!*)** + +- To show the count of remaiing content elements that can be created in a column, you can enable an integration of +content_defender in the page module +- Please understand that this feature is very experimental and does not have high priority for bug fixing + +*TYPO3 10 and 11* + +- Add the provided TypoScript template + +*TYPO3 12 and above* + +- Add the provided Page TSconfig in your page.tsconfig_includes field + ## Community - Thanks to [b13](https://b13.com) that sponsored the maintenance of this extension with a sponsorship