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,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;
}
}