Bug #81099

Extension cannot override default (fallback) templateRootPaths/partialRootPaths/partialRootPaths

Added by Christoph Bessei over 2 years ago. Updated 4 months ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2017-05-01
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
7.1
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

Description

I upgraded from 7.6 to 8.7 today and discovered a regression in TemplatePaths.php.

Wanted behaviour (TYPO3 7.6):

I have two extensions:
1. Extension "base_templates" contains a lot of fluid Partials
2. Extension "specific_templates" uses the Partials from "base_templates" and overwrites some of them.

So fluid should use the following order:
1. Check if "specific_templates" has the searched partial
2. Check if "base_templates" has the search partial

So "base_templates" is a fallback for "specific_templates".

To achieve this behaviour I configured partialRootPaths of "specific_templates":

plugin.tx_specific_templates {
    view {
        partialRootPaths {
            10 = EXT:base_templates/Resources/Private/Partials/
            20 = EXT:specific_templates/Resources/Private/Partials/
        }
    }
}

This setup worked in TYPO3 7.6 (Higher key overwrites lower key).

Actual behaviour (TYPO3 8.7):

8.7 changed the merging of default partialRootPaths and configured partialRootPaths.
The problem is "getContextSpecificViewConfiguration" in TemplatePaths.php:
https://github.com/TYPO3/TYPO3.CMS/blob/TYPO3_8-7-1/typo3/sysext/fluid/Classes/View/TemplatePaths.php#L77

Since the partialRootPaths.0 is always set to EXT:specific_templates/Resources/Private/Partials/ they always get overwritten by Partials in EXT:base_templates/Resources/Private/Partials/.
The array_merge in https://github.com/TYPO3/TYPO3.CMS/blob/TYPO3_8-7-1/typo3/sysext/fluid/Classes/View/TemplatePaths.php#L124 makes it impossible to overwrite partialRootPaths.0, because numeric array keys are not overwritten but appended.

So the result is always the following:

array (
  0 => 'BASE_PATH/www/typo3conf/ext/specific_templates/Resources/Private/Partials/',
  1 => 'BASE_PATH/www/typo3conf/ext/base_templates/Resources/Private/Partials/',
)

Wanted result:

array (
  0 => 'BASE_PATH/www/typo3conf/ext/base_templates/Resources/Private/Partials/',
  1 => 'BASE_PATH/www/typo3conf/ext/specific_templates/Resources/Private/Partials/',  
)

Possible solutions

Replace

$paths[$name] = array_merge($defaultPaths, (array)$configuredPaths[$name]);
with (used in 8.5.1 https://github.com/TYPO3/TYPO3.CMS/blob/TYPO3_8-5-1/typo3/sysext/fluid/Classes/View/TemplatePaths.php#L120)
$paths[$name] = (array)$configuredPaths[$name] + $defaultPaths;

Sadly this seems to cause other problems: #79681,#79290

Maybe we should just check if partialRootPaths.0 is explicitly set with TypoScript and in this case do not set the default partialRootPaths?

bhdummy.zip (7.2 KB) Riccardo De Contardi, 2017-08-02 13:03

cattura.png View (17.3 KB) Riccardo De Contardi, 2017-08-02 13:04


Related issues

Related to TYPO3 Core - Bug #79681: Configured Fluid template not found Closed 2017-02-08
Related to TYPO3 Core - Bug #79290: Fluid cannot override default resolved paths if default paths exist Closed 2017-01-12
Duplicated by TYPO3 Core - Bug #79926: InvalidTemplateResourceException never thrown Closed 2017-02-20

History

#1 Updated by Christoph Bessei over 2 years ago

  • Related to Bug #79681: Configured Fluid template not found added

#2 Updated by Christoph Bessei over 2 years ago

  • Related to Bug #79290: Fluid cannot override default resolved paths if default paths exist added

#3 Updated by Riccardo De Contardi about 2 years ago

Hi @Christoph Bessei, I just did the following test with the latest TYPO3 8.7.4:

1) I defined a very stupid and dummy extension (attached bhdummy.zip) that has at least one partial
2) I already use a "frontend configuration" extension (bhsiteconf) that is loaded as last in TypoScript Setup (Include static from Extension) where I copied the partial from bhdummy (and I modified it)
3) I set the constant $plugin.tx_bhdummy.view.partialRootPath so the final result is shown in Cattura.png

Result: I am not able to reproduce the issue; the partial shown is the one from

plugin.tx_bhdummy.view.partialRootPaths.1

Do you think that a different test should be done? Did I miss something? Thank you!

#4 Updated by Stephan Leithold about 2 years ago

I tested in Typo3 8.7.6. I can't override the template paths like Christoph. In Version 8.7.4 / 8.7.5 it works as expected.

#5 Updated by Urs Braem about 2 years ago

We seem to have this too in 8.7.6

#6 Updated by Sebastian Iffland about 2 years ago

Unfortunately not fixed in 8.7.7

#7 Updated by Mario Lubenka about 2 years ago

I can also confirm the issue described by Christian from 8.7.6 to 8.7.8.

#9 Updated by Riccardo De Contardi almost 2 years ago

  • Status changed from Needs Feedback to New

#10 Updated by Claus Due over 1 year ago

  • Duplicated by Bug #79926: InvalidTemplateResourceException never thrown added

#11 Updated by Riccardo De Contardi about 1 year ago

  • Status changed from New to Needs Feedback

I am not able to reproduce this issue on version 8.7.17 (see my comment 3 for the test); can you confirm it?

Moreover, the lines on the commit reported on comment 8 are changed:

        foreach ($paths as $name => $defaultPaths) {
            if (!empty($configuredPaths[$name])) {
                $paths[$name] = array_merge($defaultPaths, ArrayUtility::sortArrayWithIntegerKeys((array)$configuredPaths[$name]));
            }
        }

#12 Updated by Krzysztof Napora about 1 year ago

I have the same problem . I'm use typo3 version 8.7.18 .

Example . I have news extension and next for example I create new extension where I extend news for example so_my_news . And now we have setup for Layout, Template like here

10 => EXT: so_my_news/Resources/Private/Layouts
100 =>EXT:news/Resources/Private/Layouts/

and now you have

1 => string '/var/www/html/web/typo3conf/ext/news/Resources/Private/Layouts/'
2 => string '/var/www/html/web/typo3conf/ext/so_my_news/Resources/Private/Layouts/'

how you see the order is not the same . You can check this : typo3/cms/typo3/sysext/fluid/Classes/View/TemplatePaths function setLayoutRootPaths

#13 Updated by Riccardo De Contardi about 1 year ago

  • Status changed from Needs Feedback to New

#14 Updated by Christian Heindl about 1 year ago

Affects also 9.3. Problem still existing there.

#15 Updated by Martin Eberle 4 months ago

We just experiences a similar problem in TYPO3 version 9.5.8:

Our extension was named like „our_extension“. So we did the typoscript setup inside the extension like

plugin.tx_our_extension {
    view {
        partialRootPaths {
            0 = EXT: our_extension/Resources/Private/Partials/
            1 = {$plugin.tx_our_extension.view.partialRootPath}
        }
    }
}

and tried to overwrite it in another extension like

plugin.tx_our_extension {
    view {
        partialRootPaths {
            10 = EXT: another_extension/Resources/Private/Partials/
        }
    }
}

It didn’t work until we changed „plugin.tx_our_extension“ to „plugin.tx_ourextension“. Just without the underscore:

plugin.tx_ourextension {
    view {
        partialRootPaths {
            10 = EXT: another_extension/Resources/Private/Partials/
        }
    }
}

Also available in: Atom PDF