Commit 9ec64125 authored by Thomas Schlumberger's avatar Thomas Schlumberger Committed by Markus Klein
Browse files

[BUGFIX] Fix adding fields to an existing table in a specific position

When trying to add new fields at a specific position to an existing
table (e.g. "after:title") and the field referenced in the position is
part of a palette the regular expression to insert the new fields did
not work.

This happened because a regular expression part was inserted in the
pallete string to replace and being quoted afterwards. That caused the
preg_replace function to treat the regular expression as a string as it
has been escaped.

Resolves: #75946
Releases: master,7.6
Change-Id: Ib0dbcb56e530e1671470210218bd1c1205b50946
Reviewed-on: https://review.typo3.org/47935


Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
parent 831c2dee
......@@ -666,11 +666,12 @@ class ExtensionManagementUtility
// The $insertPosition may be a palette: after:--palette--;;title
// In the $list the palette may contain a LLL string in between the ;;
// Adjust the regex to match that
$positionName = preg_quote($positionName, '/');
if (strpos($positionName, ';;') !== false) {
$positionName = str_replace(';;', ';[^;]*;', $positionName);
}
$pattern = ('/(^|,\\s*)(' . preg_quote($positionName, '/') . ')(;[^,$]+)?(,|$)/');
$pattern = ('/(^|,\\s*)(' . $positionName . ')(;[^,$]+)?(,|$)/');
switch ($location) {
case 'after':
$newList = preg_replace($pattern, '$1$2$3, ' . $insertionList . '$4', $list);
......
......@@ -353,6 +353,21 @@ class ExtensionManagementUtilityTest extends UnitTestCase
$this->assertEquals('fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, newA, newB, fieldA, fieldZ', $GLOBALS['TCA'][$table]['types']['typeD']['showitem']);
}
/**
* Tests whether fields can be add to all TCA types and fields in pallets are respected.
*
* @test
* @see ExtensionManagementUtility::addToAllTCAtypes()
*/
public function canAddFieldsToAllTCATypesRespectsPositionFieldInPalette()
{
$table = $this->getUniqueId('tx_coretest_table');
$GLOBALS['TCA'] = $this->generateTCAForTable($table);
ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldX1');
// Checking typeA:
$this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
}
/**
* Tests whether fields can be add to a TCA type before existing ones
*
......
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