Commit 02490e99 authored by Christian Kuhn's avatar Christian Kuhn

[BUGFIX] Respect page TSConfig pid overrides for new inline children

TCAdefaults.<table>.pid = <page id> in page TSConfig can be used for
new inline children to define a pid new records should be located at,
even if the parent record is on a different page. This can be useful
when having special storage folders on a per-table-basis.

The patch fixes this feature that broke during FormEngine refactoring.

Change-Id: I8e60155612397e72f1b11a068617f88e3793384b
Resolves: #70780
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/47905Reviewed-by: 's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: 's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 8ffd696b
......@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* On "new" command, initialize new database row with default data
......@@ -47,11 +48,7 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface
$result = $this->setDefaultsFromNeighborRow($result);
$result = $this->setDefaultsFromDevVals($result);
$result = $this->setDefaultsFromInlineRelations($result);
// Set pid to vanillaUid. This means, it *can* be negative, if the record is added relative to another record
// @todo: For inline records it should be possible to set the pid here via TCAdefaults, but
// @todo: those values would be overwritten by this 'pid' setter
$result['databaseRow']['pid'] = $result['vanillaUid'];
$result = $this->setPid($result);
return $result;
}
......@@ -194,4 +191,36 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface
return $result;
}
/**
* Set the pid. This is either the vanillaUid (see description in FormDataCompiler),
* or a pid given by pageTsConfig for inline children.
*
* @param array $result Result array
* @return array Modified result array
* @throws \UnexpectedValueException
*/
protected function setPid(array $result)
{
// Set pid to vanillaUid. This can be a negative value
// if the record is added relative to another record.
$result['databaseRow']['pid'] = $result['vanillaUid'];
// In case a new inline record is created, the pid can be set to a different value
// by pageTsConfig, but not by userTsConfig. This overrides the above pid selection
// and forces the pid of new inline children.
$tableNameWithDot = $result['tableName'] . '.';
if ($result['isInlineChild'] && isset($result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'])) {
if (!MathUtility::canBeInterpretedAsInteger($result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'])) {
throw new \UnexpectedValueException(
'page TSConfig setting TCAdefaults.' . $tableNameWithDot . 'pid must be a number, but given string '
. $result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'] . ' can not be interpreted as integer',
1461598332
);
}
$result['databaseRow']['pid'] = (int)$result['pageTsConfig']['TCAdefaults.'][$tableNameWithDot]['pid'];
}
return $result;
}
}
......@@ -89,7 +89,7 @@ class DatabaseRowInitializeNewTest extends UnitTestCase
/**
* @test
*/
public function addDataSetsDefaultDataFormUserTsIfColumnIsDenfinedInTca()
public function addDataSetsDefaultDataFormUserTsIfColumnIsDefinedInTca()
{
$input = [
'command' => 'new',
......@@ -148,7 +148,7 @@ class DatabaseRowInitializeNewTest extends UnitTestCase
/**
* @test
*/
public function addDataSetsDefaultDataFormPageTsIfColumnIsDenfinedInTca()
public function addDataSetsDefaultDataFormPageTsIfColumnIsDefinedInTca()
{
$input = [
'command' => 'new',
......@@ -350,7 +350,7 @@ class DatabaseRowInitializeNewTest extends UnitTestCase
/**
* @test
*/
public function addDataSetsDefaultDataFormPostIfColumnIsDenfinedInTca()
public function addDataSetsDefaultDataFromPostIfColumnIsDenfinedInTca()
{
$input = [
'command' => 'new',
......@@ -608,4 +608,75 @@ class DatabaseRowInitializeNewTest extends UnitTestCase
$result = $this->subject->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
/**
* @test
*/
public function addDataDoesNotUsePageTsValueForPidIfRecordIsNotInlineChild()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'databaseRow' => [],
'pageTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'pid' => '42',
],
],
],
'isInlineChild' => false,
];
$expected = $input;
$expected['databaseRow']['pid'] = 23;
$this->assertSame($expected, $this->subject->addData($input));
}
/**
* @test
*/
public function addDataThrowsExceptionIfPageTsConfigPidValueCanNotBeInterpretedAsInteger()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'databaseRow' => [],
'pageTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'pid' => 'notAnInteger',
],
],
],
'isInlineChild' => true,
];
$this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1461598332);
$this->subject->addData($input);
}
/**
* @test
*/
public function addDataDoesUsePageTsValueForPidIfRecordIsInlineChild()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'databaseRow' => [],
'pageTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'pid' => '42',
],
],
],
'isInlineChild' => true,
];
$expected = $input;
$expected['databaseRow']['pid'] = 42;
$this->assertSame($expected, $this->subject->addData($input));
}
}
Markdown is supported
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