Reputation: 3711
Is it possible somehow to use some kind of explode in TCA?
What I have is a DB field looking like:
10;20;30;40-80
Now it would be nice to have some kind of explode to use a new input field or checkboxes or whatever for each string between ";" :
'number10' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_programm/locallang_db.xml:tx_mqprogramm_form.number',
'config' => array(
'type' => 'input',
'size' => '30',
)
),
'number20' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_programm/locallang_db.xml:tx_mqprogramm_form.number',
'config' => array(
'type' => 'input',
'size' => '30',
)
),
'number30' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_programm/locallang_db.xml:tx_mqprogramm_form.number',
'config' => array(
'type' => 'input',
'size' => '30',
)
),
'number40-80' => array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_programm/locallang_db.xml:tx_mqprogramm_form.number',
'config' => array(
'type' => 'input',
'size' => '30',
)
),
and so on... Ofcourse I also need them in the showitem array:
'types' => array(
'0' => array('showitem' => 'hidden;;1-1-1, number10, number20, number30, number40-80')
),
Upvotes: 0
Views: 181
Reputation: 4558
tca.php is a normal PHP file and therefore you can use PHP in there. I don't know where and how you get your DB value from, but if you have it, use it:
$fieldIdentifiers = '10;20;30;40-80';
$fieldIdentifierArray = explode(';', $fieldIdentifiers);
$dynamicFields = array();
foreach ($fieldIdentifierArray as $fieldIdentifier) {
$dynamicFields['number' . $fieldIdentifier] = array(
'exclude' => 0,
'label' => 'LLL:EXT:mq_programm/locallang_db.xml:tx_mqprogramm_form.number' . $fieldIdentifier,
'config' => array(
'type' => 'input',
'size' => '30',
),
);
}
Then merge your dynamic fields with the existing fields
$TCA['tx_mqprogramm_form']['columns'] = array_merge($TCA['tx_mqprogramm_form']['columns'], $dynamicFields);
You can use a similar way for the showitem stuff.
Don't forget to find a way to create the database field since you cannot have a dynamic ext_tables.sql.
Upvotes: 1