Commit 2978ff3b authored by Georg Ringer's avatar Georg Ringer Committed by Benni Mack

[BUGFIX] Remove dots from piVars set by _DEFAULT_PI_VARS

Make it possible to set defaults vars for plugins based on the
AbstractPlugin.

Resolves: #17283
Releases: master
Change-Id: Ic066fcf46f299554289e30eddf4529121c088881
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/58846Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarSusanne Moog <look@susi.dev>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarSusanne Moog <look@susi.dev>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
parent d0c5a1f7
......@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
......@@ -317,12 +318,34 @@ class AbstractPlugin
{
if (isset($this->conf['_DEFAULT_PI_VARS.']) && is_array($this->conf['_DEFAULT_PI_VARS.'])) {
$this->conf['_DEFAULT_PI_VARS.'] = $this->applyStdWrapRecursive($this->conf['_DEFAULT_PI_VARS.']);
$tmp = $this->conf['_DEFAULT_PI_VARS.'];
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$tmp = $typoScriptService->convertTypoScriptArrayToPlainArray($this->conf['_DEFAULT_PI_VARS.']);
ArrayUtility::mergeRecursiveWithOverrule($tmp, is_array($this->piVars) ? $this->piVars : []);
$tmp = $this->removeInternalNodeValue($tmp);
$this->piVars = $tmp;
}
}
/**
* Remove the internal array key _typoScriptNodeValue
*
* @param array $typoscript
* @return array
*/
protected function removeInternalNodeValue(array $typoscript): array
{
foreach ($typoscript as $key => $value) {
if ($key === '_typoScriptNodeValue') {
unset($typoscript[$key]);
}
if (is_array($value)) {
$typoscript[$key] = $this->removeInternalNodeValue($value);
}
}
return $typoscript;
}
/***************************
*
* Link functions
......
......@@ -35,11 +35,6 @@ class AbstractPluginTest extends UnitTestCase
*/
protected $abstractPlugin;
/**
* @var array
*/
protected $defaultPiVars;
/**
* @var bool
*/
......@@ -63,7 +58,6 @@ class AbstractPluginTest extends UnitTestCase
'TEXT' => TextContentObject::class,
]);
$this->abstractPlugin->cObj = $contentObjectRenderer;
$this->defaultPiVars = $this->abstractPlugin->piVars;
}
/**
......@@ -82,13 +76,18 @@ class AbstractPluginTest extends UnitTestCase
'wrap' => 'test | test'
],
],
'simplevalue' => 'lipsum'
],
[
'abc' => 'testDEFtest',
'simplevalue' => 'lipsum',
'pointer' => '',
'mode' => '',
'sword' => '',
'sort' => '',
'a' => [
'bit' => 'nested'
]
],
],
'stdWrap on conf, non-recursive, stdWrap 2 levels deep' => [
......@@ -109,6 +108,9 @@ class AbstractPluginTest extends UnitTestCase
'mode' => '',
'sword' => '',
'sort' => '',
'a' => [
'bit' => 'nested'
]
],
],
'stdWrap on conf, recursive' => [
......@@ -122,18 +124,55 @@ class AbstractPluginTest extends UnitTestCase
],
],
],
'simple_value' => '45'
],
[
'abc' => [
'def' => [
'ghi' => '123',
],
],
'simple_value' => '45',
'pointer' => '',
'mode' => '',
'sword' => '',
'sort' => '',
'a' => [
'bit' => 'nested'
]
],
],
'stdWrap on conf, recursive, default pivars get overridden recursive nested set' => [
[
'abc.' => [
'def' => 'testDEFtest',
'def' => 'DEF',
'def.' => [
'ghi' => '123',
'stdWrap.' => [
'wrap' => 'test | test'
],
],
],
'a' => [
'default-is' => 'uncool'
],
'simple_value' => '45'
],
[
'abc' => [
'def' => [
'ghi' => '123',
],
],
'simple_value' => '45',
'pointer' => '',
'mode' => '',
'sword' => '',
'sort' => '',
'a' => [
'default-is' => 'uncool',
'bit' => 'nested'
]
],
],
];
......@@ -146,7 +185,7 @@ class AbstractPluginTest extends UnitTestCase
public function piSetPiVarDefaultsStdWrap($input, $expected)
{
$this->resetSingletonInstances = true;
$this->abstractPlugin->piVars = $this->defaultPiVars;
$this->abstractPlugin->piVars['a']['bit'] = 'nested';
$this->abstractPlugin->conf['_DEFAULT_PI_VARS.'] = $input;
$this->abstractPlugin->pi_setPiVarDefaults();
......
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