Navigation Menu

Skip to content

Commit

Permalink
[BUGFIX] Restore altIcons TSconfig option
Browse files Browse the repository at this point in the history
In #35891 a feature was introduced, which allowed to
override the icon of select items via Page TSconfig.

This feature however did more or less never see the LTS
release, since it was almost completely removed in #67006
again.

Only SelectMultipleSideBySide provided this feature until
https://review.typo3.org/c/Packages/TYPO3.CMS/+/50879/.

It's now restored, using the original configuration path.

Resolves: #73227
Relates: #35891
Releases: master, 10.4
Change-Id: I40e243a6f62a82ddf373b59977b61d00501777fd
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68776
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
o-ba authored and bmack committed Apr 16, 2021
1 parent 5afe600 commit 881906e
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 4 deletions.
Expand Up @@ -948,6 +948,29 @@ public function translateLabels(array $result, array $itemArray, $table, $fieldN
return $itemArray;
}

/**
* Add alternative icon using "altIcons" TSconfig
*
* @param array $result
* @param array $items
* @param string $table
* @param string $fieldName
*
* @return array
*/
public function addIconFromAltIcons(array $result, array $items, string $table, string $fieldName): array
{
foreach ($items as &$item) {
if (isset($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altIcons.'][$item[1]])
&& !empty($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altIcons.'][$item[1]])
) {
$item[2] = $result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altIcons.'][$item[1]];
}
}

return $items;
}

/**
* Sanitize incoming item array
*
Expand Down
Expand Up @@ -148,6 +148,9 @@ public function addData(array $result): array
// Translate labels
$fieldConfig['config']['items'] = $this->translateLabels($result, $fieldConfig['config']['items'], $table, $fieldName);

// Add icons
$fieldConfig['config']['items'] = $this->addIconFromAltIcons($result, $fieldConfig['config']['items'], $table, $fieldName);

$result['processedTca']['columns'][$fieldName] = $fieldConfig;
}

Expand Down
Expand Up @@ -107,10 +107,11 @@ public function addData(array $result)
$removedItems
);

// Translate labels
// Translate labels and add icons
// skip file of sys_file_metadata which is not rendered anyway but can use all memory
if (!($table === 'sys_file_metadata' && $fieldName === 'file')) {
$fieldConfig['config']['items'] = $this->translateLabels($result, $fieldConfig['config']['items'], $table, $fieldName);
$fieldConfig['config']['items'] = $this->addIconFromAltIcons($result, $fieldConfig['config']['items'], $table, $fieldName);
}

// Keys may contain table names, so a numeric array is created
Expand Down
Expand Up @@ -128,8 +128,10 @@ public function addData(array $result)
// itemsProcFunc must not be used anymore
unset($fieldConfig['config']['itemsProcFunc']);
}
// And translate any labels from the static list
// translate any labels
$staticItems = $this->translateLabels($result, $staticItems, $table, $fieldName);
// and add icons from the static list
$staticItems = $this->addIconFromAltIcons($result, $staticItems, $table, $fieldName);
// Now compile the target items using the same array structure as the "dynamic" list below
foreach ($staticItems as $item) {
if ($item[1] === '--div--') {
Expand Down
Expand Up @@ -475,6 +475,46 @@ public function addDataRespectsAltLabels(): void
);
}

/**
* @test
*/
public function addDataRespectsAltIcons(): void
{
$input = $this->getDefaultResultArray(
[],
$this->getDefaultSystemLanguages(),
[],
[
'pageTsConfig' => [
'TCEFORM.' => [
'aTable.' => [
'aField.' => [
'altIcons.' => [
'0' => 'alternative-icon-default',
'14' => 'alternative-icon-german'
],
],
],
],
],
]
);

$expected = [
['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.siteLanguages', '--div--', null, null, null],
['English', 0, 'alternative-icon-default', null, null],
['Danish', 13, 'flags-dk', null, null],
['German', 14, 'alternative-icon-german', null, null],
['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.specialLanguages', '--div--', null, null, null],
['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages', -1, 'flags-multiple', null, null]
];

self::assertEquals(
$expected,
(new TcaLanguage())->addData($input)['processedTca']['columns']['aField']['config']['items']
);
}

/**
* @test
*/
Expand Down
Expand Up @@ -2636,6 +2636,61 @@ public function addDataTranslatesItemLabelsFromPageTsConfig(): void
self::assertSame($expected, (new TcaSelectItems())->addData($input));
}

/**
* @test
*/
public function addDataAddsIconsFromPageTsConfig(): void
{
$input = [
'databaseRow' => [
'aField' => 'aValue',
],
'tableName' => 'aTable',
'processedTca' => [
'columns' => [
'aField' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
0 => [
0 => 'aLabel',
1 => 'aValue',
2 => 'icon-identifier',
null,
null
],
],
'maxitems' => 99999,
],
],
],
],
'pageTsConfig' => [
'TCEFORM.' => [
'aTable.' => [
'aField.' => [
'altIcons.' => [
'aValue' => 'icon-identifier-override',
],
]
],
],
],
];

$languageService = $this->prophesize(LanguageService::class);
$GLOBALS['LANG'] = $languageService->reveal();
$languageService->sL('aLabel')->willReturnArgument(0);
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn('INVALID VALUE "%s"');

$expected = $input;
$expected['databaseRow']['aField'] = ['aValue'];
$expected['processedTca']['columns']['aField']['config']['items'][0][2] = 'icon-identifier-override';

self::assertSame($expected, (new TcaSelectItems())->addData($input));
}

/**
* @test
*/
Expand Down
Expand Up @@ -237,7 +237,10 @@ public function addDataHandsPageTsConfigSettingsOverToTableConfigurationTree()
'childrenField' => 'childrenField'
],
'foreign_table' => 'foreignTable',
'items' => [],
'items' => [
[ 'static item foo', 1, 'foo-icon' ],
[ 'static item bar', 2, 'bar-icon' ],
],
'maxitems' => 1
],
],
Expand All @@ -257,18 +260,32 @@ public function addDataHandsPageTsConfigSettingsOverToTableConfigurationTree()
],
],
],
'altLabels.' => [
1 => 'alt static item foo',
2 => 'alt static item bar'
],
'altIcons.' => [
1 => 'foo-alt-icon',
2 => 'bar-alt-icon'
],
],
],
],
],
'selectTreeCompileItems' => true,
];

(new TcaSelectTreeItems())->addData($input);
$result = (new TcaSelectTreeItems())->addData($input);

$treeDataProviderProphecy->setRootUid(42)->shouldHaveBeenCalled();
$treeDataProviderProphecy->setExpandAll(true)->shouldHaveBeenCalled();
$treeDataProviderProphecy->setLevelMaximum(4)->shouldHaveBeenCalled();
$treeDataProviderProphecy->setNonSelectableLevelList('0,1')->shouldHaveBeenCalled();

$resultItems = $result['processedTca']['columns']['aField']['config']['items'];
self::assertEquals('alt static item foo', $resultItems[0]['name']);
self::assertEquals('foo-alt-icon', $resultItems[0]['icon']);
self::assertEquals('alt static item bar', $resultItems[1]['name']);
self::assertEquals('bar-alt-icon', $resultItems[1]['icon']);
}
}
@@ -0,0 +1,32 @@
.. include:: ../../Includes.txt

=====================================================
Important: #73227 - TSconfig option altIcons restored
=====================================================

See :issue:`73227`

Description
===========

The TSconfig option :typoscript:`altIcons`, introduced in :issue:`#35891`,
allowed to add / override icons for TCA select items. This option was then
accidentally removed without further notice, while reworking the FormEngine.

Therefore and because it's sometimes necessary to use different icons for
already defined select items - depending on the current page or site context -
the option is restored.

The usage is as following:

.. code-block:: typoscript
TCEFORM.pages.doktype.altIcons {
1 = custom-icon-identifier
2 = EXT:my_ext/path/to/icon.svg
}
For more information you can also have a look at the initial
:doc:`changelog <../7.1/Feature-35891-AddTCAItemsWithIconsViaPageTSConfig>`.

.. index:: Backend, TSConfig, ext:backend

0 comments on commit 881906e

Please sign in to comment.