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?
Updated by Gerrit Code Review about 1 year ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81746
Updated by Gerrit Code Review about 1 year ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81746
Updated by Oliver Bartsch about 1 year ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 1b0893377b8109c4c474c0a80d3d7b8aba957ea3.
Updated by Gerrit Code Review about 1 year ago
- Status changed from Resolved to Under Review
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81767
Updated by Oliver Bartsch about 1 year ago
- Status changed from Under Review to Resolved
Applied in changeset ed0c3997ad8b7dc4ea0ffb854de017638b83c988.