Manipulate TCA-values with itemsProcFunc
Example: Manipulate TCA for a given field with conditions
- Conditions are only when startPid is true and colpos = 2 or 3 or 4
- field is tt_content.layout
In Configuration/TCA/Overrides/tt_content.php add itemsProcFunc to TCA:
$GLOBALS['TCA']['tt_content']['columns']['layout']['config']['itemsProcFunc'] = \Vender\Name\Tca\LayoutOptions::class . '->filterOptions';
In Vender\Name\Tca\LayoutOptions.php:
<?php
declare(strict_types=1);
namespace Vendor\Name\Tca;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\TypoScriptService;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class LayoutOptions {
private int $startPid = 1;
public function __construct() {
$this->startPid = $this->getTypoScriptConstant('site.startPid', $this->startPid);
}
public function filterOptions(array &$config) {
// Get TypoScript constant for start page PID
$startPid = $this->getTypoScriptConstant('site.startPid', 1); // Default to 1 if not found
$currentPageUid = (int)$config['row']['pid'];
$currentColPos = (int)($config['row']['colPos'] ?? 0);
// Set your Startpage UID and colPos
if ($currentPageUid === 1 && ($currentColPos === 2 || $currentColPos === 3 || $currentColPos === 4)) {
$config['items'] = [
['kein Icon', 0],
['University', 1],
['Home',2],
['Check square',3],
];
}
}
private function getTypoScriptConstant(string $constant, int $defaultValue): int
{
if (isset($GLOBALS['TSFE']) && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$typoScriptArray = $typoScriptService->convertTypoScriptArrayToPlainArray($GLOBALS['TSFE']->tmpl->setup);
return isset($typoScriptArray[$constant]) ? (int)$typoScriptArray[$constant] : $defaultValue;
}
return $defaultValue;
}
}
In Fluid
There are four values concerning the field layout:
<f:variable name="icon1" value="fa fa-home fa-hidden" />
<f:switch expression="{info1.layout}">
<f:case value="1">
<f:variable name="icon1" value="fa fa-university" />
</f:case>
<f:case value="2">
<f:variable name="icon1" value="fa fa-home" />
</f:case>
<f:case value="3">
<f:variable name="icon1" value="fa fa-check-square-o" />
</f:case>
</f:switch>