Bug #102366
closedHardcoded type check in ElementBrowser.php prevents class extensions
100%
Description
Since the TCA field type folder
doesn't support 'l10n_display' => 'defaultAsReadonly'
(which it really shoud!), we decided to define our own form field type to check for the language and set readonly
to true, if not in the default language. We defined a TCA field with a config section like this:
'config' => [
'type' => 'user',
'renderType' => 'uploadFolderField',
'maxitems' => 1,
'size' => 1,
],
We then defined the class for the new renderType something like this:
class UploadFolderElement extends \TYPO3\CMS\Backend\Form\Element\FolderElement
{
public function render()
{
// -> add own functionality
return parent::render();
}
}
This will result in a "Field controls must return a title" exception thrown in \TYPO3\CMS\Backend\Form\NodeExpansion\FieldControl
.
After some digging and debugging it turns out that this is caused by a type check in \TYPO3\CMS\Backend\Form\FieldControl\ElementBrowser
:
$title = '';
if ($type === 'group') {
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_db';
} elseif ($type === 'folder') {
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_folder';
}
Since the type will be user
in our example, you will always run into this exception. Only allowing group
and folder
as valid types basically prevents extensions of form fields that use the element browser.
There should either be a sensible default for $title
or a way to define an alternative title via TCA.
BTW, as a workaround you can force the type back to one of the allowed values before calling the parent's render method:
$this->data['parameterArray']['fieldConf']['config']['type'] = 'folder';
But that's not really the idea of class extensions, is it?