How to remove a field from `showitems` in TCA?
Asked Answered
B

2

6

TYPO3 has the function TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes() to add or replace one or more fields to the BE form of a record.

How can we remove fields?
(replacing by '' does not work)


Explanation:
Its about hiding some fields in tt_content for some CTypes only.
In the past we did it by overwriting the complete value. But with the upgrade from 6.2LTS to 8LTS we run into problems as the default labels have changed (pathes to the language files) and so some labels become lost in the BE, which was noticed very late.
Now I want a clean way to remove single fields so that the definition of the remaining fields stays clean with the default values from core (or other extensions).

Other extensiosn which add their own fields also are a problem if the value is set with a static string: these fields are also removed.

Barner answered 4/12, 2019 at 8:24 Comment(2)
I don't think I quite understand why pageTSConfig is not an option? Usually, when I need to remove fields from specific CEs from the backend, I usually do TCEFORM.tt_content.[field].types.[CType].disabled = 1.Larva
I don't understand the explanation and why tsconfig is not an option.Azikiwe
B
5

Since there is indeed no way to insert an empty string, you could create an empty palette instead. This way you will still get a non empty string to insert, but it will not create any output in the form.

addToAllTCAtypes('table', '--palette--;;empty', '', 'replace:fieldname')

And you should make a feature request, to make at least the replacement with an empty string possible in upcoming versions of TYPO3.

Beatrisbeatrisa answered 4/12, 2019 at 15:53 Comment(1)
feature request can be found as forge.typo3.org/issues/89852Snailfish
R
0

Do it in the code like this:

foreach ($GLOBALS['TCA']['yourtablenamehere']['types'] as &$definition) {
  $definition['showitems'] = '';
}

if you only need to reset a specific type ('0', for example):

$GLOBALS['TCA']['yourtablenamehere']['types']['0']['showitems'] = '';

If you want to override types completely instead of clearing them (clearing only does not much sense anyway):

$GLOBALS['TCA']['yourtablenamehere']['types']['0']['showitems'] = 'title, bodytext';
Raila answered 4/12, 2019 at 8:34 Comment(3)
Or using pageTSConfig "TCEFORM.[tableName].[fieldName].disabled"Showalter
I added some explanation to show, why these suggestions are no solution.Snailfish
@BerndWilkeπφ Using them successfully since TYPO3 3.6.x ;)Raila

© 2022 - 2024 — McMap. All rights reserved.