Commit e9f52844 authored by Johannes Schlier's avatar Johannes Schlier Committed by Christian Kuhn
Browse files

[BUGFIX] Allow RTE transformations in palettes

When having an RTE inside a palette (e.g. sys_file_reference
description field changed to a RTE field) then the RTE configuration
is not taken into account, thus it's not possible to do proper
transformations. All links are not working then.

The patch allows to parse the fields inside palettes as well.

Resolves: #60399
Resolves: #76745
Releases: master, 7.6
Change-Id: I0c4efc0a03682cd766a2a164cf7b2fa14cd7c1b9
Reviewed-on: https://review.typo3.org/49201


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 9f307625
......@@ -752,6 +752,25 @@ class BackendUtility
}
}
// Add palette fields e.g. for a valid RTE transformation
$paletteFieldList = [];
foreach ($fieldList as $fieldData) {
list($pFieldName, $pAltTitle, $pPalette) = GeneralUtility::trimExplode(';', $fieldData);
if ($pPalette
&& isset($GLOBALS['TCA'][$table]['palettes'][$pPalette])
&& is_array($GLOBALS['TCA'][$table]['palettes'][$pPalette])
&& isset($GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'])
) {
$paletteFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['palettes'][$pPalette]['showitem'], true);
foreach ($paletteFields as $paletteField) {
if ($paletteField !== '--linebreak--') {
$paletteFieldList[] = $paletteField;
}
}
}
}
$fieldList = array_merge($fieldList, $paletteFieldList);
$altFieldList = [];
// Traverse fields in types config and parse the configuration into a nice array:
foreach ($fieldList as $k => $v) {
......
......@@ -1133,4 +1133,278 @@ class BackendUtilityTest extends UnitTestCase
$this->assertSame('24-03-16 00:00 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400));
$this->assertSame('24-03-16 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400, 1, 'date'));
}
///////////////////////////////////////
// Tests concerning getTCAtypes
///////////////////////////////////////
/**
* @test
*/
public function getTCAtypesReturnsCorrectValuesDataProvider()
{
return [
'no input' => [
'', // table
[], // rec
'', // useFieldNameAsKey
null // expected
],
'non-existant table' => [
'fooBar', // table
[], // rec
'', // useFieldNameAsKey
null // expected
],
'Doktype=1: one simple field' => [
'pages',
[
'uid' => '1',
'doktype' => '1'
],
false,
[
0 => [
'field' => 'title',
'title' => null,
'palette' => null,
'spec' => [],
'origString' => 'title'
]
]
],
'non-existant type given: Return for type 1' => [
'pages', // table
[
'uid' => '1',
'doktype' => '999'
], // rec
'', // useFieldNameAsKey
[
0 => [
'field' => 'title',
'title' => null,
'palette' => null,
'spec' => [],
'origString' => 'title'
]
] // expected
],
'Doktype=1: one simple field, useFieldNameAsKey=true' => [
'pages',
[
'uid' => '1',
'doktype' => '1'
],
true,
[
'title' => [
'field' => 'title',
'title' => null,
'palette' => null,
'spec' => [],
'origString' => 'title'
]
]
],
'Empty showitem Field' => [
'test',
[
'uid' => '1',
'fooBar' => '99'
],
true,
[
'' => [
'field' => '',
'title' => null,
'palette' => null,
'spec' => [],
'origString' => ''
]
]
],
'RTE field within a palette' => [
'pages',
[
'uid' => '1',
'doktype' => '10',
],
false,
[
0 => [
'field' => '--div--',
'title' => 'General',
'palette' => null,
'spec' => [],
'origString' => '--div--;General'
],
1 => [
'field' => '--palette--',
'title' => 'Palette',
'palette' => '123',
'spec' => [],
'origString' => '--palette--;Palette;123'
],
2 => [
'field' => 'title',
'title' => null,
'palette' => null,
'spec' => [],
'origString' => 'title'
],
3 => [
'field' => 'text',
'title' => null,
'palette' => null,
'spec' => [
'richtext' => 1,
'rte_transform' => [
'parameters' => [
0 => 'mode=ts_css'
]
]
],
'origString' => 'text'
],
4 => [
'field' => 'select',
'title' => 'Select field',
'palette' => null,
'spec' => [],
'origString' => 'select;Select field'
]
]
],
'RTE field with more settings within a palette' => [
'pages',
[
'uid' => 1,
'doktype' => 2
],
false,
[
0 => [
'field' => '--div--',
'title' => 'General',
'palette' => null,
'spec' => [],
'origString' => '--div--;General'
],
1 => [
'field' => '--palette--',
'title' => 'RTE palette',
'palette' => '456',
'spec' => [],
'origString' => '--palette--;RTE palette;456'
],
2 => [
'field' => 'text2',
'title' => null,
'palette' => null,
'spec' => [
'richtext' => 1,
'rte_transform' => [
'parameters' => [
0 => 'mode=fooBar,type=RTE'
]
]
],
'origString' => 'text2'
]
]
]
];
}
/**
* @test
* @dataProvider getTCAtypesReturnsCorrectValuesDataProvider
*
* @param string $table
* @param array $rec
* @param bool $useFieldNameAsKey
* @param array $expected
*/
public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
{
$GLOBALS['TCA'] = [
'pages' => [
'ctrl' => [
'type' => 'doktype'
],
'columns' => [
'title' => [
'label' => 'Title test',
'config' => [
'type' => 'input'
]
],
'text' => [
'label' => 'RTE Text',
'config' => [
'type' => 'text',
'cols' => 40,
'rows' => 5
],
'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
],
'text2' => [
'label' => 'RTE Text 2',
'config' => [
'type' => 'text',
'cols' => 40,
'rows' => 5
],
'defaultExtras' => 'richtext:rte_transform[mode=fooBar,type=RTE]'
],
'select' => [
'label' => 'Select test',
'config' => [
'items' => [
['Please select', 0],
['Option 1', 1],
['Option 2', 2]
]
],
'maxitems' => 1,
'renderType' => 'selectSingle'
]
],
'types' => [
'1' => [
'showitem' => 'title'
],
'2' => [
'showitem' => '--div--;General,--palette--;RTE palette;456'
],
'10' => [
'showitem' => '--div--;General,--palette--;Palette;123,title'
],
'14' => [
'showitem' => '--div--;General,title'
]
],
'palettes' => [
'123' => [
'showitem' => 'text,select;Select field'
],
'456' => [
'showitem' => 'text2'
]
]
],
'test' => [
'ctrl' => [
'type' => 'fooBar'
],
'types' => [
'99' => [ 'showitem' => '']
]
]
];
$return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
$this->assertSame($expected, $return);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment