Skip to content

Commit

Permalink
[BUGFIX] Ensure title is set for ElementBrowser
Browse files Browse the repository at this point in the history
FieldControl is required to set a title.
To ensure this, the field control options
can now be used to set a custom title.

Additionally, a fallback is added to ensure
a title is always set, even if a custom
TCA type is used and no title is defined,
using the FieldControl option.

Resolves: #102366
Releases: main, 12.4
Change-Id: Id4b2bbb15d5e1d12fae6dbd287dbdeda7ba5b987
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81767
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Nov 18, 2023
1 parent 9601e48 commit ed0c399
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
Expand Up @@ -38,6 +38,7 @@ public function render()
{
$table = $this->data['tableName'];
$fieldName = $this->data['fieldName'];
$options = $this->data['renderData']['fieldControlOptions'];
$parameterArray = $this->data['parameterArray'];
$elementName = $parameterArray['itemFormElName'];
$config = $parameterArray['fieldConf']['config'];
Expand All @@ -50,11 +51,15 @@ public function render()
return [];
}

$title = '';
if ($type === 'group') {
if ($options['title'] ?? false) {
$title = $options['title'];
} elseif ($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';
} else {
// FieldControl requires to provide a title -> Set default if non is given and custom TCA config is used
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_elements';
}

// Check against inline uniqueness - Create some onclick js for delete control and element browser
Expand Down
Expand Up @@ -35,6 +35,9 @@ public function renderTrimsAllowedValuesFromConfigSection(): void
'isInlineChild' => false,
'tableName' => 'tt_content',
'inlineStructure' => [],
'renderData' => [
'fieldControlOptions' => [],
],
'parameterArray' => [
'itemFormElName' => '',
'fieldConf' => [
Expand All @@ -61,6 +64,9 @@ public function renderTrimsAllowedValues(): void
'isInlineChild' => false,
'tableName' => 'tt_content',
'inlineStructure' => [],
'renderData' => [
'fieldControlOptions' => [],
],
'parameterArray' => [
'itemFormElName' => '',
'fieldConf' => [
Expand Down Expand Up @@ -89,6 +95,9 @@ public function renderResolvesEntryPoint(array $config, string $expected): void
'site' => new Site('some-site', 123, []),
'tableName' => 'tt_content',
'inlineStructure' => [],
'renderData' => [
'fieldControlOptions' => [],
],
'parameterArray' => [
'itemFormElName' => '',
'fieldConf' => [
Expand Down Expand Up @@ -224,4 +233,63 @@ public static function renderResolvesEntryPointDataProvider(): \Generator
'123',
];
}

/**
* @test
*/
public function renderUsesCustomTitle(): void
{
$title = 'Custom title';
$nodeFactory = $this->createMock(NodeFactory::class);
$elementBrowser = new ElementBrowser($nodeFactory, [
'fieldName' => 'somefield',
'isInlineChild' => false,
'tableName' => 'tt_content',
'renderData' => [
'fieldControlOptions' => [
'title' => $title,
],
],
'inlineStructure' => [],
'parameterArray' => [
'itemFormElName' => '',
'fieldConf' => [
'config' => [
'type' => 'group',
'allowed' => 'pages',
],
],
],
]);
$result = $elementBrowser->render();
self::assertSame($title, $result['title']);
}

/**
* @test
*/
public function renderUsesFallbackTitle(): void
{
$nodeFactory = $this->createMock(NodeFactory::class);
$elementBrowser = new ElementBrowser($nodeFactory, [
'fieldName' => 'somefield',
'isInlineChild' => false,
'tableName' => 'tt_content',
'renderData' => [
'fieldControlOptions' => [],
],
'inlineStructure' => [],
'parameterArray' => [
'itemFormElName' => '',
'fieldConf' => [
'config' => [
'type' => 'user',
'allowed' => 'pages',
],
],
],
]);
$result = $elementBrowser->render();
self::assertSame('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_elements', $result['title']);
}
}
Expand Up @@ -382,6 +382,9 @@ Do you want to continue WITHOUT saving?</source>
<trans-unit id="labels.move" resname="labels.move">
<source>Move this item</source>
</trans-unit>
<trans-unit id="labels.browse_elements" resname="labels.browse_elemets">
<source>Browse for elements</source>
</trans-unit>
<trans-unit id="labels.browse_folder" resname="labels.browse_folder">
<source>Browse for folders</source>
</trans-unit>
Expand Down

0 comments on commit ed0c399

Please sign in to comment.