diff --git a/Classes/Backend/CategoryWarningDrawer.php b/Classes/Backend/CategoryWarningDrawer.php new file mode 100644 index 0000000000000000000000000000000000000000..d367c102a106c88183729f1649cdf67eb610a23d --- /dev/null +++ b/Classes/Backend/CategoryWarningDrawer.php @@ -0,0 +1,88 @@ +<?php +/* + * Copyright notice + * + * (c) sgalinski Internet Services (https://www.sgalinski.de) + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + */ + +namespace SGalinski\SgNews\Backend; + +use SGalinski\SgNews\Domain\Model\Category; +use TYPO3\CMS\Backend\Controller\PageLayoutController; +use TYPO3\CMS\Core\Database\Connection; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * + */ +class CategoryWarningDrawer { + + /** + * @var LanguageService + */ + protected $languageService; + + public function __construct(LanguageService $languageService) { + $this->languageService = $languageService; + } + + /** + * @param array|NULL $params + * @param PageLayoutController|NULL $parentObj + * @return string + * @throws \Doctrine\DBAL\Driver\Exception + */ + public function render(array $params = null, PageLayoutController $parentObj = null): string { + $parentPage = $parentObj->pageinfo['pid']; + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('pages'); + $parentDoktype = $queryBuilder->select('doktype') + ->from('pages') + ->where( + $queryBuilder->expr()->eq( + 'uid', + $queryBuilder->createNamedParameter($parentPage, Connection::PARAM_INT) + ) + )->execute() + ->fetchOne(); + if ($parentDoktype === Category::DOK_TYPE_CATEGORY) { + return ''; + } + + $message = GeneralUtility::makeInstance(FlashMessage::class, + $this->languageService->sL( + 'LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:categoryErrorMessage' + ), + $this->languageService->sL( + 'LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:categoryErrorMessageHeader' + ), + FlashMessage::ERROR, + true + ); + return GeneralUtility::makeInstance(FlashMessageRendererResolver::class) + ->resolve() + ->render([$message]); + } +} diff --git a/Resources/Private/Language/de.locallang_backend.xlf b/Resources/Private/Language/de.locallang_backend.xlf index 84fb9572271fc163b3944f1f35845f63a5870ac6..72e55203dab9ee6140cef6a0f2112d322c584579 100644 --- a/Resources/Private/Language/de.locallang_backend.xlf +++ b/Resources/Private/Language/de.locallang_backend.xlf @@ -93,6 +93,14 @@ <source><![CDATA[News Single View]]></source> <target><![CDATA[News Einzelansicht]]></target> </trans-unit> + <trans-unit id="categoryErrorMessageHeader"> + <source><![CDATA[No category found]]></source> + <target><![CDATA[Keine Kategorie gefunden]]></target> + </trans-unit> + <trans-unit id="categoryErrorMessage"> + <source><![CDATA[This news has no category. Please put it into a category or the rendering will be errorneous. The category most not be hidden, either.]]></source> + <target><![CDATA[Dieser Beitrag ist keiner Kategorie zugewiesen. Bitte verschieben Sie ihn in eine Kategorie, damit die Darstellung korrekt funktioniert. Die Kategorie darf nicht versteckt sein.]]></target> + </trans-unit> </body> </file> -</xliff> \ No newline at end of file +</xliff> diff --git a/Resources/Private/Language/locallang_backend.xlf b/Resources/Private/Language/locallang_backend.xlf index fdcf2f9cd0c4d56ee87dbb70bc939300eb941c35..f3fda9e64f7548122403c639aaaa1870ed86193f 100644 --- a/Resources/Private/Language/locallang_backend.xlf +++ b/Resources/Private/Language/locallang_backend.xlf @@ -78,6 +78,12 @@ <trans-unit id="titleSingleViewPlugin"> <source><![CDATA[News Single View]]></source> </trans-unit> + <trans-unit id="categoryErrorMessageHeader"> + <source><![CDATA[No category found]]></source> + </trans-unit> + <trans-unit id="categoryErrorMessage"> + <source><![CDATA[This news has no category. Please put it into a category or the rendering will be errorneous. The category most not be hidden, either.]]></source> + </trans-unit> </body> </file> -</xliff> \ No newline at end of file +</xliff> diff --git a/ext_localconf.php b/ext_localconf.php index 050de5bb24d54bb615a436ea248bdc11858932f4..ad84ad089d4d95200e909cb469dee7e52fb23de5 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -95,6 +95,8 @@ call_user_func( 'SGalinski\SgNews\TCA\TcaProvider'; $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['sg_news'] = \SGalinski\SgNews\Hooks\PageLayoutView\PluginRenderer::class; + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] + = \SGalinski\SgNews\Backend\CategoryWarningDrawer::class . '->render'; // Xclasses $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\CMS\Core\Page\PageRenderer'] =