Skip to content
Snippets Groups Projects
Commit 5814b35b authored by Nicole Cordes's avatar Nicole Cordes Committed by Alexander Opitz
Browse files

[BUGFIX] Correctly deprecate globals usage in FormEngine

Resolves: #84530
Releases: master
Change-Id: Idb8fc143d7126840f0d964697b2a6dbe71e72cb3
Reviewed-on: https://review.typo3.org/56443


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: default avatarTobi Kretschmann <tobi@tobishome.de>
Reviewed-by: default avatarSteffen Frese <steffenf14@gmail.com>
Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
parent 1b08b298
Branches
Tags
No related merge requests found
...@@ -131,6 +131,7 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface ...@@ -131,6 +131,7 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface
*/ */
protected function setDefaultsFromDefaultValues(array $result) protected function setDefaultsFromDefaultValues(array $result)
{ {
$result = $this->setDefaultValuesFromGetPost($result);
$tableName = $result['tableName']; $tableName = $result['tableName'];
$defaultValues = $result['defaultValues'] ?? []; $defaultValues = $result['defaultValues'] ?? [];
if (isset($defaultValues[$tableName]) && is_array($defaultValues[$tableName])) { if (isset($defaultValues[$tableName]) && is_array($defaultValues[$tableName])) {
...@@ -143,6 +144,30 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface ...@@ -143,6 +144,30 @@ class DatabaseRowInitializeNew implements FormDataProviderInterface
return $result; return $result;
} }
/**
* @param array $result
* @return array
* @deprecated since v9 will be removed in v10 - see $result['defaultValues']
*/
protected function setDefaultValuesFromGetPost(array $result)
{
if (!empty($result['defaultValues'])) {
return $result;
}
$defaultValues = GeneralUtility::_GP('defVals');
if (!empty($defaultValues)) {
trigger_error(
'Default values for new database rows should be set from controller context. Applying default values'
. ' via GET/POST parameters is deprecated since 9.2 and will be removed in version 10',
\E_USER_DEPRECATED
);
$result['defaultValues'] = $defaultValues;
}
return $result;
}
/** /**
* Inline scenario if a new intermediate record to an existing child-child is * Inline scenario if a new intermediate record to an existing child-child is
* compiled. Set "foreign_selector" field of this intermediate row to given * compiled. Set "foreign_selector" field of this intermediate row to given
......
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowInitializeNew;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test case for TcaFlexPrepare to render the functionality when a TCA migration happened
*/
class DatabaseRowInitializeNewTest extends UnitTestCase
{
/**
* @test
*/
public function addDataSetsDefaultDataFromGetIfColumnIsDefinedInTca()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'neighborRow' => null,
'inlineChildChildUid' => null,
'isInlineChild' => false,
'databaseRow' => [],
'processedTca' => [
'columns' => [
'aField' => [],
],
],
];
$GLOBALS['_GET'] = [
'defVals' => [
'aTable' => [
'aField' => 'getValue',
],
],
];
$expected = [
'aField' => 'getValue',
'pid' => 23,
];
$result = (new DatabaseRowInitializeNew())->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
/**
* @test
*/
public function addDataSetsDefaultDataFromPostIfColumnIsDefinedInTca()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'neighborRow' => null,
'inlineChildChildUid' => null,
'isInlineChild' => false,
'databaseRow' => [],
'processedTca' => [
'columns' => [
'aField' => [],
],
],
];
$GLOBALS['_POST'] = [
'defVals' => [
'aTable' => [
'aField' => 'postValue',
],
],
];
$expected = [
'aField' => 'postValue',
'pid' => 23,
];
$result = (new DatabaseRowInitializeNew())->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
/**
* @test
*/
public function addDataSetsPrioritizesDefaultPostOverDefaultGet()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'neighborRow' => null,
'inlineChildChildUid' => null,
'isInlineChild' => false,
'databaseRow' => [],
'processedTca' => [
'columns' => [
'aField' => [],
],
],
];
$GLOBALS['_GET'] = [
'defVals' => [
'aTable' => [
'aField' => 'getValue',
],
],
];
$GLOBALS['_POST'] = [
'defVals' => [
'aTable' => [
'aField' => 'postValue',
],
],
];
$expected = [
'aField' => 'postValue',
'pid' => 23,
];
$result = (new DatabaseRowInitializeNew())->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
/**
* @test
*/
public function addDataDoesNotSetDefaultDataFromGetPostIfColumnIsMissingInTca()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'neighborRow' => null,
'inlineChildChildUid' => null,
'isInlineChild' => false,
'databaseRow' => [],
'userTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'aField' => 'pageTsValue',
],
],
],
'processedTca' => [
'columns' => [],
],
];
$GLOBALS['_GET'] = [
'defVals' => [
'aTable' => [
'aField' => 'getValue',
],
],
];
$GLOBALS['_POST'] = [
'defVals' => [
'aTable' => [
'aField' => 'postValue',
],
],
];
$expected = [
'pid' => 23,
];
$result = (new DatabaseRowInitializeNew())->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
/**
* @test
*/
public function addDataSetsDefaultDataOverrulingGetPost()
{
$input = [
'command' => 'new',
'tableName' => 'aTable',
'vanillaUid' => 23,
'inlineChildChildUid' => null,
'isInlineChild' => false,
'databaseRow' => [],
'neighborRow' => [
'aField' => 'valueFromNeighbor',
],
'pageTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'aField' => 'pageTsValue',
],
],
],
'userTsConfig' => [
'TCAdefaults.' => [
'aTable.' => [
'aField' => 'userTsValue',
],
],
],
'processedTca' => [
'ctrl' => [
'useColumnsForDefaultValues' => 'aField',
],
'columns' => [
'aField' => [],
],
],
];
$GLOBALS['_POST'] = [
'defVals' => [
'aTable' => [
'aField' => 'postValue',
],
],
];
$expected = [
'aField' => 'postValue',
'pid' => 23,
];
$result = (new DatabaseRowInitializeNew())->addData($input);
$this->assertSame($expected, $result['databaseRow']);
}
}
.. include:: ../../Includes.txt
==========================================================================
Deprecation: #84530 - Default values from globals deprecated in FormEngine
==========================================================================
See :issue:`84530`
Description
===========
Setting default values for new database records from GET/POST `defVals` parameter
has been deprecated in 9.2 and will be removed in version 10.
Impact
======
If not already provided within the new configuration setting `$result['defaultValues']`, the
default values are applied from GET/POST `defVals` configuration, but will trigger a
deprecation warning.
Affected Installations
======================
Installations that use the FormEngine within extensions might need to be changed.
Migration
=========
Use the `defaultValues` configuration to set default values for new database rows
in the \TYPO3\CMS\Backend\Form\FormDataCompiler::compile call.
.. index:: Backend, PHP-API, NotScanned
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