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} + + + + + + + +