Initial commit - Typo3 11.5.41

This commit is contained in:
Matteo Gallo
2026-07-03 17:53:31 +02:00
commit 5ca4743197
6811 changed files with 568848 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace GeorgRinger\News\Backend\FormDataProvider;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace GeorgRinger\News\Backend\FieldInformation;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Localization\LanguageService;
class StaticText extends AbstractNode
{
/**
* Handler for single nodes
*
* @return array
*/
public function render(): array
{
$languageService = $this->getLanguageService();
$labels = [];
foreach ((array)($this->data['renderData']['fieldInformationOptions']['labels'] ?? []) as $labelConfiguration) {
$label = htmlspecialchars($languageService->sL($labelConfiguration['label']));
if (!empty($labelConfiguration['italic'])) {
$label = '<em>' . $label . '</em>';
}
if (!empty($labelConfiguration['bold'])) {
$label = '<strong>' . $label . '</strong>';
}
$labels[] = $label;
}
return [
'requireJsModules' => [
'TYPO3/CMS/News/TagSuggestWizard',
],
'html' => '<div class="form-control-wrap news-taggable">'
. implode('<br />', $labels)
. '</div>',
];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}

View File

@@ -0,0 +1,282 @@
<?php
namespace GeorgRinger\News\Backend\FormDataProvider;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use GeorgRinger\News\Domain\Model\Dto\EmConfiguration;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Fill the news records with default values
*/
class NewsFlexFormManipulation implements FormDataProviderInterface
{
/**
* Fields which are removed in detail view
*
* @var array
*/
protected $removedFieldsInDetailView = [
'sDEF' => [
'orderBy', 'orderDirection', 'categories', 'categoryConjunction', 'includeSubCategories',
'archiveRestriction', 'timeRestriction', 'timeRestrictionHigh', 'topNewsRestriction',
'dateField'
],
'additional' => [
'limit', 'offset', 'hidePagination', 'topNewsFirst', 'listPid', 'list.paginate.itemsPerPage'
],
'template' => [ 'cropMaxCharacters' ],
];
/**
* Fields which are removed in list view
*
* @var array
*/
protected $removedFieldsInListView = [
'sDEF' => [
'dateField', 'singleNews', 'previewHiddenRecords'
],
'additional' => [],
'template' => [],
];
/**
* Fields which are removed in dateMenu view
*
* @var array
*/
protected $removedFieldsInDateMenuView = [
'sDEF' => [
'orderBy', 'singleNews'
],
'additional' => [
'limit', 'offset', 'hidePagination', 'topNewsFirst' , 'backPid', 'previewHiddenRecords', 'excludeAlreadyDisplayedNews',
'list.paginate.itemsPerPage'
],
'template' => [
'cropMaxCharacters', 'media.maxWidth', 'media.maxHeight'
],
];
/**
* Fields which are removed in search form view
*
* @var array
*/
protected $removedFieldsInSearchFormView = [
'sDEF' => [
'orderBy', 'orderDirection', 'categories', 'categoryConjunction', 'includeSubCategories',
'archiveRestriction', 'timeRestriction', 'timeRestrictionHigh', 'topNewsRestriction',
'startingpoint', 'recursive', 'dateField', 'singleNews', 'previewHiddenRecords'
],
'additional' => [
'limit', 'offset', 'hidePagination', 'topNewsFirst', 'detailPid', 'backPid', 'excludeAlreadyDisplayedNews',
'list.paginate.itemsPerPage'
],
'template' => [
'cropMaxCharacters', 'media.maxWidth', 'media.maxHeight'
],
];
/**
* Fields which are removed in category list view
*
* @var array
*/
protected $removedFieldsInCategoryListView = [
'sDEF' => [
'orderBy', 'orderDirection', 'categoryConjunction', 'includeSubCategories',
'archiveRestriction', 'timeRestriction', 'timeRestrictionHigh', 'topNewsRestriction',
'recursive', 'dateField', 'singleNews', 'previewHiddenRecords',
],
'additional' => [
'limit', 'offset', 'hidePagination', 'topNewsFirst', 'detailPid', 'backPid', 'excludeAlreadyDisplayedNews',
'list.paginate.itemsPerPage'
],
'template' => [
'cropMaxCharacters', 'media.maxWidth', 'media.maxHeight'
],
];
/**
* Fields which are removed in tag list view
*
* @var array
*/
protected $removedFieldsInTagListView = [
'sDEF' => [
'categories', 'categoryConjunction', 'includeSubCategories',
'archiveRestriction', 'timeRestriction', 'timeRestrictionHigh', 'topNewsRestriction',
'dateField', 'singleNews', 'previewHiddenRecords'
],
'additional' => [
'hidePagination', 'topNewsFirst', 'detailPid', 'backPid', 'excludeAlreadyDisplayedNews',
'list.paginate.itemsPerPage'
],
'template' => [
'cropMaxCharacters', 'media.maxWidth', 'media.maxHeight'
]
];
/**
* @var EmConfiguration
*/
protected $configuration;
public function __construct()
{
$this->configuration = GeneralUtility::makeInstance(EmConfiguration::class);
}
/**
* Remove fields depending on switchable controller action in tt_content
* Restrict category selection based on configuration in tt_content
*
* @param array $result
* @return array
*/
public function addData(array $result): array
{
if ($result['tableName'] === 'tt_content'
&& $result['databaseRow']['CType'] === 'list'
&& $result['databaseRow']['list_type'] === 'news_pi1'
&& is_array($result['processedTca']['columns']['pi_flexform']['config']['ds'])
) {
$result = $this->updateFlexForms($result);
if ($this->enabledInTsConfig($result)) {
$result = $this->addCategoryConstraints($result);
}
}
return $result;
}
/**
* Update flexform configuration if a action is selected
*
* @param array $result Full data
* @return array Modified data
*/
protected function updateFlexForms(array $result): array
{
$selectedView = '';
$row = $result['databaseRow'];
$dataStructure = $result['processedTca']['columns']['pi_flexform']['config']['ds'];
// get the first selected action
$flexformSelection = $row['pi_flexform'];
if (is_array($flexformSelection)
&& is_array($flexformSelection['data'])
&& !empty($flexformSelection['data']['sDEF']['lDEF']['switchableControllerActions']['vDEF'])
) {
$selectedView = $flexformSelection['data']['sDEF']['lDEF']['switchableControllerActions']['vDEF'];
$actionParts = GeneralUtility::trimExplode(';', $selectedView, true);
$selectedView = $actionParts[0];
} elseif ($result['command'] === 'new') {
// new plugin element, use List as starting view
$selectedView = 'News->list';
}
if (!empty($selectedView)) {
// Modify the flexform structure depending on the first found action
switch ($selectedView) {
case 'News->list':
case 'News->searchResult':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInListView);
break;
case 'News->detail':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInDetailView);
break;
case 'News->searchForm':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInSearchFormView);
break;
case 'News->dateMenu':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInDateMenuView);
break;
case 'Category->list':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInCategoryListView);
break;
case 'Tag->list':
$dataStructure = $this->deleteFromStructure($dataStructure, $this->removedFieldsInTagListView);
break;
default:
}
$params = [
'selectedView' => $selectedView,
'dataStructure' => &$dataStructure,
];
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Hooks/BackendUtility.php']['updateFlexforms'] ?? [] as $reference) {
GeneralUtility::callUserFunction($reference, $params, $this);
}
}
$result['processedTca']['columns']['pi_flexform']['config']['ds'] = $dataStructure;
return $result;
}
/**
* Add category restriction to flexforms
*
* @param array $result
* @return array Modified result
*/
protected function addCategoryConstraints($result): array
{
$structure = $result['processedTca']['columns']['pi_flexform']['config']['ds'];
$categoryRestrictionSetting = $this->configuration->getCategoryRestriction();
$categoryRestriction = '';
switch ($categoryRestrictionSetting) {
case 'current_pid':
$categoryRestriction = ' AND sys_category.pid=###CURRENT_PID### ';
break;
case 'siteroot':
$categoryRestriction = ' AND sys_category.pid IN (###SITEROOT###) ';
break;
case 'page_tsconfig':
$categoryRestriction = ' AND sys_category.pid IN (###PAGE_TSCONFIG_IDLIST###) ';
break;
}
if (!empty($categoryRestriction) && isset($structure['sheets']['sDEF']['ROOT']['el']['settings.categories'])) {
$structure['sheets']['sDEF']['ROOT']['el']['settings.categories']['config']['foreign_table_where'] = $categoryRestriction . $structure['sheets']['sDEF']['ROOT']['el']['settings.categories']['config']['foreign_table_where'];
}
$result['processedTca']['columns']['pi_flexform']['config']['ds'] = $structure;
return $result;
}
/**
* Remove fields from flexform structure
*
* @param array &$dataStructure flexform structure
* @param array $fieldsToBeRemoved fields which need to be removed
* @return array Modified structure
*/
protected function deleteFromStructure(array $dataStructure, array $fieldsToBeRemoved): array
{
foreach ($fieldsToBeRemoved as $sheetName => $fieldsInSheet) {
foreach ($fieldsInSheet as $fieldName) {
unset($dataStructure['sheets'][$sheetName]['ROOT']['el']['settings.' . $fieldName]);
}
}
return $dataStructure;
}
/**
* @param array $result Incoming array
* @return bool
*/
protected function enabledInTsConfig(array $result): bool
{
return (bool)($result['pageTsConfig']['tx_news.']['categoryRestrictionForFlexForms'] ?? false);
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace GeorgRinger\News\Backend\FormDataProvider;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use GeorgRinger\News\Domain\Model\Dto\EmConfiguration;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Fill the news records with default values
*/
class NewsRowInitializeNew implements FormDataProviderInterface
{
/** @var EmConfiguration */
protected $emConfiguration;
public function __construct()
{
$this->emConfiguration = GeneralUtility::makeInstance(EmConfiguration::class);
}
/**
* @param array $result
* @return array
*/
public function addData(array $result): array
{
if ($result['tableName'] !== 'tx_news_domain_model_news') {
return $result;
}
$result = $this->setTagListingId($result);
if ($result['command'] === 'new') {
$result = $this->fillDateField($result);
}
return $result;
}
/**
* @param array $result
* @return array
*/
protected function fillDateField(array $result): array
{
if ($this->emConfiguration->getDateTimeRequired()) {
$result['databaseRow']['datetime'] = $GLOBALS['EXEC_TIME'];
}
if (isset($result['pageTsConfig']['tx_news.']['predefine.'])
&& is_array($result['pageTsConfig']['tx_news.']['predefine.'])
) {
if (isset($result['pageTsConfig']['tx_news.']['predefine.']['author']) && (int)$result['pageTsConfig']['tx_news.']['predefine.']['author'] === 1) {
$result['databaseRow']['author'] = $GLOBALS['BE_USER']->user['realName'];
$result['databaseRow']['author_email'] = $GLOBALS['BE_USER']->user['email'];
}
if (isset($result['pageTsConfig']['tx_news.']['predefine.']['archive'])) {
$calculatedTime = strtotime($result['pageTsConfig']['tx_news.']['predefine.']['archive']);
if ($calculatedTime !== false) {
$result['databaseRow']['archive'] = $calculatedTime;
}
}
}
return $result;
}
/**
* @param array $result
* @return array
*/
protected function setTagListingId(array $result): array
{
if (!isset($result['pageTsConfig']['tx_news.']['tagPid'])) {
return $result;
}
$tagPid = (int)$result['pageTsConfig']['tx_news.']['tagPid'];
if ($tagPid <= 0) {
return $result;
}
$result['processedTca']['columns']['tags']['config']['fieldControl']['listModule']['options']['pid'] = $tagPid;
return $result;
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace GeorgRinger\News\Backend\RecordList;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
/**
* Class for the list rendering of administration module
*/
class NewsDatabaseRecordList extends DatabaseRecordList
{
/**
* Creates the URL to this script, including all relevant GPvars
* Fixed GPvars are id, table, imagemode, returnUrl, search_field, search_levels and showLimit
* The GPvars "sortField" and "sortRev" are also included UNLESS they are found in the $excludeList variable.
*
* @param string $alternativeId Alternative id value. Enter blank string for the current id ($this->id)
* @param string $excludeList Comma separated list of fields NOT to include ("sortField" or "sortRev")
* @return string
*/
public function listURL($alternativeId = '', $table = '-1', $excludeList = ''): string
{
$urlParameters = [];
if ((string)$alternativeId !== '') {
$urlParameters['id'] = $alternativeId;
} else {
$urlParameters['id'] = $this->id;
}
if (isset($this->thumbs)) {
$urlParameters['imagemode'] = $this->thumbs;
}
if ($this->returnUrl) {
$urlParameters['returnUrl'] = $this->returnUrl;
}
if ($this->searchString) {
$urlParameters['search_field'] = $this->searchString;
}
if ($this->searchLevels) {
$urlParameters['search_levels'] = $this->searchLevels;
}
if ($this->showLimit) {
$urlParameters['showLimit'] = $this->showLimit;
}
if (isset($this->firstElementNumber)) {
$urlParameters['pointer'] = $this->firstElementNumber;
}
if ((!$excludeList || !GeneralUtility::inList(
$excludeList,
'sortField'
)) && $this->sortField
) {
$urlParameters['sortField'] = $this->sortField;
}
if ((!$excludeList || !GeneralUtility::inList(
$excludeList,
'sortRev'
)) && $this->sortRev
) {
$urlParameters['sortRev'] = $this->sortRev;
}
if (GeneralUtility::_GP('SET')) {
$urlParameters['SET'] = GeneralUtility::_GP('SET');
}
if (GeneralUtility::_GP('show')) {
$urlParameters['show'] = (int)GeneralUtility::_GP('show');
}
$demand = GeneralUtility::_GET('tx_news_web_newsadministration');
if (isset($demand['demand']) && is_array($demand['demand'])) {
$urlParameters['tx_news_web_newsadministration']['demand'] = $demand['demand'];
}
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return $uriBuilder->buildUriFromRoute('web_NewsAdministration', $urlParameters);
}
}

View File

@@ -0,0 +1,259 @@
<?php
namespace GeorgRinger\News\Backend\RecordList;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use GeorgRinger\News\Service\CategoryService;
use GeorgRinger\News\Utility\ConstraintHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class for the list rendering of administration module
*/
class RecordListConstraint
{
const TABLE = 'tx_news_domain_model_news';
/**
* Check if current module is the news administration module
*
* @return bool
*/
public function isInAdministrationModule(): bool
{
$vars = GeneralUtility::_GET('route');
return strpos($vars, '/module/web/NewsAdministration') !== false;
}
public function extendQuery(array &$parameters, array $arguments): void
{
$parameters['whereDoctrine'] = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_news_domain_model_news');
$expressionBuilder = $queryBuilder->expr();
// search word
if (isset($arguments['searchWord']) && !empty($arguments['searchWord'])) {
$words = GeneralUtility::trimExplode(' ', $arguments['searchWord'], true);
$fields = ['title', 'teaser', 'bodytext'];
$fieldParts = [];
foreach ($fields as $field) {
$likeParts = [];
$nameParts = str_getcsv($arguments['searchWord'], ' ');
foreach ($nameParts as $part) {
$part = trim($part);
if ($part !== '') {
$likeParts[] = $expressionBuilder->like($field, $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($part) . '%'));
}
}
if (!empty($likeParts)) {
$fieldParts[] = $expressionBuilder->orX(...$likeParts);
}
}
$parameters['whereDoctrine'][] = $expressionBuilder->orX(...$fieldParts);
$parameters['where'][] = $expressionBuilder->orX(...$fieldParts);
}
// top news
$topNewsSetting = (int)$arguments['topNewsRestriction'];
if ($topNewsSetting > 0) {
if ($topNewsSetting === 1) {
$parameters['where'][] = 'istopnews=1';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('istopnews', 1);
} elseif ($topNewsSetting === 2) {
$parameters['where'][] = 'istopnews=0';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('istopnews', 0);
}
}
// archived (1==active, 2==archived)
$archived = (int)$arguments['archived'];
if ($archived > 0) {
$currentTime = $GLOBALS['EXEC_TIME'];
if ($archived === 1) {
$parameters['where'][] = '(archive > ' . $currentTime . ' OR archive=0)';
$parameters['whereDoctrine'][] = $expressionBuilder->orX(
$expressionBuilder->gt('archive', $currentTime),
$expressionBuilder->eq('archive', 0)
);
} elseif ($archived === 2) {
$parameters['where'][] = 'archive > 0 AND archive <' . $currentTime;
$parameters['whereDoctrine'][] = $expressionBuilder->andX(
$expressionBuilder->gt('archive', 0),
$expressionBuilder->lt('archive', $currentTime)
);
}
}
// hidden
$hidden = (int)$arguments['hidden'];
if ($hidden > 0) {
if ($hidden === 1) {
$parameters['where'][] = 'hidden=1';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('hidden', 1);
} elseif ($hidden === 2) {
$parameters['where'][] = 'hidden=0';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('hidden', 0);
}
}
// time constraint low
if (isset($arguments['timeRestriction']) && !empty($arguments['timeRestriction'])) {
try {
$limit = ConstraintHelper::getTimeRestrictionLow($arguments['timeRestriction']);
$parameters['where'][] = 'datetime >=' . $limit;
$parameters['whereDoctrine'][] = $expressionBuilder->gte('datetime', $limit);
} catch (\Exception $e) {
// @todo add flash message
}
}
// time constraint high
if (isset($arguments['timeRestrictionHigh']) && !empty($arguments['timeRestrictionHigh'])) {
try {
$limit = ConstraintHelper::getTimeRestrictionHigh($arguments['timeRestrictionHigh']);
$parameters['where'][] = 'datetime <=' . $limit;
$parameters['whereDoctrine'][] = $expressionBuilder->lte('datetime', $limit);
} catch (\Exception $e) {
// @todo add flash message
}
}
// categories
if (isset($arguments['selectedCategories']) && is_array($arguments['selectedCategories'])) {
$categoryMode = strtolower($arguments['categoryConjunction']);
foreach ($arguments['selectedCategories'] as $key => $category) {
if ((int)$category === 0) {
unset($arguments['selectedCategories'][$key]);
}
}
if (!empty($arguments['selectedCategories'])) {
if ((int)$arguments['includeSubCategories'] === 1) {
$categoryList = implode(',', $arguments['selectedCategories']);
$listWithSubCategories = CategoryService::getChildrenCategories($categoryList);
$arguments['selectedCategories'] = explode(',', $listWithSubCategories);
}
switch ($categoryMode) {
case 'and':
foreach ($arguments['selectedCategories'] as $category) {
$idList = $this->getNewsIdsOfCategory($category);
if (empty($idList)) {
$parameters['where'][] = '1=2';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('uid', 0);
} else {
$parameters['where'][] = sprintf('uid IN(%s)', implode(',', $idList));
$parameters['whereDoctrine'][] = $expressionBuilder->in('uid', $idList);
}
}
break;
case 'or':
$orConstraint = $orConstraintDoctrine = [];
foreach ($arguments['selectedCategories'] as $category) {
$idList = $this->getNewsIdsOfCategory($category);
if (!empty($idList)) {
$orConstraint[] = sprintf('uid IN(%s)', implode(',', $idList));
$orConstraintDoctrine[] = $expressionBuilder->in('uid', $idList);
}
}
if (empty($orConstraint)) {
$parameters['where'][] = '1=2';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('uid', 0);
} else {
$parameters['where'][] = implode(' OR ', $orConstraint);
$parameters['whereDoctrine'][] = $expressionBuilder->orX(...$orConstraintDoctrine);
}
break;
// @todo test that
case 'notor':
$orConstraint = $orConstraintDoctrine = [];
foreach ($arguments['selectedCategories'] as $category) {
$idList = $this->getNewsIdsOfCategory($category);
if (!empty($idList)) {
$orConstraint[] = sprintf('(uid IN (%s))', implode(',', $idList));
$orConstraintDoctrine[] = $expressionBuilder->notIn('uid', $idList);
} else {
$orConstraint[] = '1=2';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('uid', 0);
}
}
if (empty($orConstraint)) {
$parameters['where'][] = '1=2';
$parameters['whereDoctrine'][] = $expressionBuilder->eq('uid', 0);
} else {
$orConstraint = array_unique($orConstraint);
$parameters['where'][] = ' NOT (' . implode(' OR ', $orConstraint) . ')';
$parameters['whereDoctrine'][] = $expressionBuilder->andX(...$orConstraintDoctrine);
}
break;
case 'notand':
foreach ($arguments['selectedCategories'] as $category) {
$idList = $this->getNewsIdsOfCategory($category);
if (!empty($idList)) {
$parameters['where'][] = sprintf('uid NOT IN(%s)', implode(',', $idList));
$parameters['whereDoctrine'][] = $expressionBuilder->notIn('uid', $idList);
}
}
break;
}
}
}
// order
if (isset($arguments['sortingField']) && isset($GLOBALS['TCA']['tx_news_domain_model_news']['columns'][$arguments['sortingField']])) {
$direction = ($arguments['sortingDirection'] === 'asc' || $arguments['sortingDirection'] === 'desc') ? $arguments['sortingDirection'] : '';
$parameters['orderBy'] = [[$arguments['sortingField'], $direction]];
}
}
/**
* @param int $categoryId
* @return array
*/
protected function getNewsIdsOfCategory($categoryId): array
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_news_domain_model_news');
$queryBuilder->getRestrictions()
->removeByType(StartTimeRestriction::class)
->removeByType(HiddenRestriction::class)
->removeByType(EndTimeRestriction::class);
$res = $queryBuilder
->select('tx_news_domain_model_news.uid', 'sys_category.title')
->from('tx_news_domain_model_news')
->rightJoin(
'tx_news_domain_model_news',
'sys_category_record_mm',
'sys_category_record_mm',
$queryBuilder->expr()->eq('tx_news_domain_model_news.uid', $queryBuilder->quoteIdentifier('sys_category_record_mm.uid_foreign'))
)
->rightJoin(
'sys_category_record_mm',
'sys_category',
'sys_category',
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->quoteIdentifier('sys_category_record_mm.uid_local'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->isNotNull('tx_news_domain_model_news.uid'),
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->createNamedParameter($categoryId, \PDO::PARAM_INT))
)
->execute();
$idList = [];
while ($row = $res->fetch()) {
$idList[] = $row['uid'];
}
return $idList;
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace GeorgRinger\News\Backend\Wizard;
use GeorgRinger\News\Domain\Model\Dto\EmConfiguration;
use TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver;
use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
class SuggestWizardReceiver extends SuggestWizardDefaultReceiver
{
public function queryTable(&$params, $recursionCounter = 0)
{
$rows = parent::queryTable($params, $recursionCounter);
$searchString = strtolower($params['value']);
$matchRow = array_filter($rows, function ($value) use ($searchString) {
return strtolower($value['label']) === $searchString;
});
if (empty($matchRow)) {
$newUid = StringUtility::getUniqueId('NEW');
$rows[$this->table . '_' . $newUid] = [
'class' => '',
'label' => $params['value'],
'path' => '',
'sprite' => $this->iconFactory->getIconForRecord($this->table, [], Icon::SIZE_SMALL)->render(),
'style' => '',
'table' => $this->table,
'text' => sprintf($this->getLanguageService()->sL('LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:tag_suggest'), $params['value']),
'uid' => $newUid,
];
$configuration = GeneralUtility::makeInstance(EmConfiguration::class);
$pid = $configuration->getTagPid();
if ($pid === 0) {
$pid = $this->getTagPidFromTsConfig($params['uid']);
}
if ($pid !== 0) {
$rows[$this->table . '_' . $newUid]['pid'] = $pid;
}
}
return $rows;
}
/**
* Get pid for tags from TsConfig
*
* @param int $newsUid uid of current news record
* @return int
*/
protected function getTagPidFromTsConfig($newsUid): int
{
$pid = 0;
$newsRecord = BackendUtilityCore::getRecord('tx_news_domain_model_news', (int)$newsUid);
$pagesTsConfig = BackendUtilityCore::getPagesTSconfig($newsRecord['pid']);
if (isset($pagesTsConfig['tx_news.']) && isset($pagesTsConfig['tx_news.']['tagPid'])) {
$pid = (int)$pagesTsConfig['tx_news.']['tagPid'];
}
return $pid;
}
}