Skip to content
Snippets Groups Projects
Commit c68090f2 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

[TASK] Avoid constructor argument of TemplatePaths

A previous patch already avoided calls to the constructor
of `TemplatePaths`, which is deprecated if called with an
argument since Fluid v2.15. This follow-up covers remaining
places.

Furthermore, both usages of `GeneralUtility::makeInstance()`
are converted to `new` to harmonize the creation of those
objects in the Core. Now every occurrences use `new`.

`ksort()` is removed because this is done internally in
`TemplatePaths` setters. It was necessary before because
of the merging behavior of `extractPathArrays()`, which
is no longer used now (and is also deprecated in Fluid).

Resolves: #104860
Related: #104823
Releases: main
Change-Id: Ic16638e8512f6272dbd52bbf0f65fb405b8483cf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85926


Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarSimon Praetorius <simon@praetorius.me>
Reviewed-by: default avatarSimon Praetorius <simon@praetorius.me>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent f8d767b4
Branches
Tags
No related merge requests found
......@@ -162,31 +162,20 @@ class EmailFinisher extends AbstractFinisher
protected function initializeTemplatePaths(array $globalConfig, array $localConfig): TemplatePaths
{
if (is_array($localConfig['templateRootPaths'] ?? null)) {
$globalConfig['templateRootPaths'] = array_replace_recursive(
$globalConfig['templateRootPaths'],
$localConfig['templateRootPaths']
);
ksort($globalConfig['templateRootPaths']);
}
if (is_array($localConfig['partialRootPaths'] ?? null)) {
$globalConfig['partialRootPaths'] = array_replace_recursive(
$globalConfig['partialRootPaths'],
$localConfig['partialRootPaths']
);
ksort($globalConfig['partialRootPaths']);
}
if (is_array($localConfig['layoutRootPaths'] ?? null)) {
$globalConfig['layoutRootPaths'] = array_replace_recursive(
$globalConfig['layoutRootPaths'],
$localConfig['layoutRootPaths']
);
ksort($globalConfig['layoutRootPaths']);
}
return GeneralUtility::makeInstance(TemplatePaths::class, $globalConfig);
$templatePaths = new TemplatePaths();
$templatePaths->setTemplateRootPaths(array_replace(
$globalConfig['templateRootPaths'] ?? [],
$localConfig['templateRootPaths'] ?? [],
));
$templatePaths->setLayoutRootPaths(array_replace(
$globalConfig['layoutRootPaths'] ?? [],
$localConfig['layoutRootPaths'] ?? [],
));
$templatePaths->setPartialRootPaths(array_replace(
$globalConfig['partialRootPaths'] ?? [],
$localConfig['partialRootPaths'] ?? [],
));
return $templatePaths;
}
protected function initializeFluidEmail(FormRuntime $formRuntime): FluidEmail
......
......@@ -52,16 +52,16 @@ final class EmailFinisherTest extends UnitTestCase
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
],
],
],
......@@ -91,17 +91,17 @@ final class EmailFinisherTest extends UnitTestCase
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
'EXT:myextension/Resources/Private/Templates/Form/Email/',
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
20 => 'EXT:myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
],
],
],
......@@ -138,22 +138,22 @@ final class EmailFinisherTest extends UnitTestCase
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
'path/to/myextension/Resources/Private/Templates/Email/',
'path/to/myextension/Resources/Private/Templates/Form/Email/',
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
20 => 'path/to/myextension/Resources/Private/Templates/Email/',
100 => 'path/to/myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
'path/to/myextension/Resources/Private/Layouts/Email/',
'path/to/myextension/Resources/Private/Layouts/Form/Email/',
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
20 => 'path/to/myextension/Resources/Private/Layouts/Email/',
100 => 'path/to/myextension/Resources/Private/Layouts/Form/Email/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
'path/to/myextension/Resources/Private/Partials/Email/',
'path/to/myextension/Resources/Private/Partials/Form/Email/',
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
20 => 'path/to/myextension/Resources/Private/Partials/Email/',
100 => 'path/to/myextension/Resources/Private/Partials/Form/Email/',
],
],
],
......
......@@ -506,14 +506,13 @@ class ValidatorTask extends AbstractTask
*/
protected function getFluidEmail(): FluidEmail
{
$templateConfiguration = array_replace_recursive(
$GLOBALS['TYPO3_CONF_VARS']['MAIL'],
['templateRootPaths' => [20 => 'EXT:linkvalidator/Resources/Private/Templates/Email/']]
);
// must be sorted after adding the default path to ensure already registered custom paths are called first
ksort($templateConfiguration['templateRootPaths']);
$templatePaths = GeneralUtility::makeInstance(TemplatePaths::class, $templateConfiguration);
$templatePaths = new TemplatePaths();
$templatePaths->setTemplateRootPaths(array_replace(
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'] ?? [],
[20 => 'EXT:linkvalidator/Resources/Private/Templates/Email/'],
));
$templatePaths->setLayoutRootPaths($GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'] ?? []);
$templatePaths->setPartialRootPaths($GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths'] ?? []);
if ($this->emailTemplateName === '' || !$this->templateFilesExist($templatePaths->getTemplateRootPaths())) {
// Add default template name to task if empty or given template name does not exist
......
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