1
votes

I have created a custom content element without extending the tt_content columns because the existing fields in the database are sufficient for what I need.

I am using "header", "header_link" and "image" but I need the "image" column to have a different TCA configuration when it's used in my custom content element.

I can change the configuration globally:

$GLOBALS['TCA']['tt_content']['columns']['image']['config']['maxitems'] = 1;

but that's not what I want.

Something like

$GLOBALS['TCA']['tt_content']['my_custom_element']['columns']['image']['config']['maxitems'] = 1;

or

$GLOBALS['TCA']['tt_content']['columns']['my_custom_element']['image']['config']['maxitems'] = 1;

isn't working.

Does anyone know how to accomplish what I want? Thanks! :-)

4

4 Answers

3
votes

It's not documented yet but the following code works in TYPO3 7.3

$GLOBALS['TCA']['tt_content']['types']['my_custom_element']['columnsOverrides'] = array(
  'image' => array(
    'config' => array(
      'maxitems' => 1
    )
  )
);
1
votes

@dmnkhhn is right. below is your solution if your TYPO3 CMS version is newer or equal to TYPO3 CMS 7.3

$GLOBALS['TCA']['tt_content']['types'][$myCType]['columnsOverrides']['images']['config']['maxitems'] = 1;

Note that you have to configure you new plugin type as a ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT for this to work.

Example

Take a look at the Configuration backend module TCA section and browse to (foldout) tt_content/types/html/columnsOverrides and see how the TYPO3 core handles the override of the bodytext field for the HTML content element.

The Configuration backend module is a great tool to learn and understand TCA and other global variables by seeing how other already has done the thing you want.

0
votes

TCA config of columns is some kind of final, that means they are cached once and it's not possible to use different configs for one field depending on any conditions.

The typical solution is adding custom image field ie. my_image to the tt_content and replacing original image field within your CE type only

like (sample):

$GLOBALS['TCA']['tt_content']['types']['Tx_Your_Type']['showitem'] = $GLOBALS['TCA']['tt_content']['types']['image']['showitem'];
$GLOBALS['TCA']['tt_content']['types']['Tx_Your_Type']['showitem'] = str_replace(',image ,', ',my_image ,', $GLOBALS['TCA']['tt_content']['types']['Tx_Your_Type']['showitem']);
0
votes

Override a field with the the configuration of another column like this:

$GLOBALS['TCA']['tt_content']['types']['myType']['columnsOverrides']['header']['config'] = 
    $GLOBALS['TCA']['tt_content']['columns']['header_link']['config'];