Skip to content
Snippets Groups Projects
Verified Commit 107d3820 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Add a message to show when a news got no category

parent 687abd41
No related branches found
No related tags found
No related merge requests found
<?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'];
  • Owner

    Das kommt doch jetzt auf jeder Seite als Fehler. Inwiefern werden hier nur News geprüft?

  • Please register or sign in to reply
$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]);
}
}
......@@ -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>
......@@ -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>
......@@ -97,6 +97,8 @@ call_user_func(
\SGalinski\SgNews\TCA\TcaProvider::class;
$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'][]
  • Owner

    An Matthias übergeben zwecks Test, ob das in TYPO3 11 überhaupt noch geht.

  • Please register or sign in to reply
= \SGalinski\SgNews\Backend\CategoryWarningDrawer::class . '->render';
// Xclasses
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Core\Page\PageRenderer::class] =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment