1

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 Answers 4

3

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

@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

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']);
4
  • I've already tried to create a new column: $GLOBALS['TCA']['tt_content']['columns']['my_custom_element_image'] = $GLOBALS['TCA']['tt_content']['columns']['image']; $GLOBALS['TCA']['tt_content']['columns']['my_custom_element_image']['config']['maxitems'] = 1; … and adding that new column to my CE type but I can't save the element because 'my_custom_element_image' is not a column in the tt_content table.
    – dmnkhhn
    Jun 24, 2015 at 11:54
  • Cause you need it also in ext_tables.sql, take a look here for some samples: docs.typo3.org/typo3cms/TCAReference/ExtendingTca/Examples/… ... BTW which version of TYPO3 exactly do you use? add proper tags to your question.
    – biesior
    Jun 24, 2015 at 12:05
  • I am using TYPO3 7.3 – besides that I am fully aware that a custom column requires the column also to be present in the ext_tables.sql. A new column was not what I intended to create. I was hoping for a solution that allows me to use the existing columns, just with a new configuration for a custom content element.
    – dmnkhhn
    Jun 24, 2015 at 12:18
  • How we can override imagecols items list i need only 2,3,4,6 items.but seems columnoverride does'nt help.it just change list but didn't remove any default items. Aug 28, 2017 at 15:02
0

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'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.