#108779Plugin's partial can be inaccessible if there are multiple partialRootPaths
Description
This seems to be similar to #81099. It was fixed for TYPO3 v11 & v12 but in v13 the fixed method is deprecated and not used.
Suppose I use EXT:news and want to extend the NewsController with new views. I create a EXT:test/Classes/Controller/MyNewsController and register my own plugin. I want to reuse some partials of EXT:news (like List/Detail but I want to override some others (like List/Item). Here is what I do in TS:
plugin.tx_test.view {
partialRootPaths {
10 = EXT:news/Resources/Private/Partials/
15 = EXT:eventnews/Resources/Private/Partials/
20 = EXT:test/Resources/Private/Partials/
}
}
According to the documentation it should search EXT:test/Resources/Private/Partials/ for partials and if it cannot find the partial there, it should search EXT:news/Resources/Private/Partials/ , right?
Wrong.
The actual order becomes:
[ 0 => 'EXT:test/Resources/Private/Partials/', 1 => 'EXT:news/Resources/Private/Partials/', 2 => 'EXT:eventnews/Resources/Private/Partials/', ]
So partials from EXT:news will always be used and not mine.
Why?
Look at ActionController::resolveView() :
$partialRootPaths = ['EXT:' . $extensionKey . '/Resources/Private/Partials/'];
if (!empty($configuration['view']['partialRootPaths']) && is_array($configuration['view']['partialRootPaths'])) {
$partialRootPaths = array_merge($partialRootPaths, ArrayUtility::sortArrayWithIntegerKeys($configuration['view']['partialRootPaths']));
}
So $partialRootPaths becomes:
[ 0 => 'EXT:test/Resources/Private/Partials/', 10 => 'EXT:news/Resources/Private/Partials/', 15 => 'EXT:eventnews/Resources/Private/Partials/', 20 => 'EXT:test/Resources/Private/Partials/', ]
Still good, though there is a duplicate of my path.
Next we have TemplatePaths::setLayoutRootPaths(), which calls ArrayUtility::sortArrayWithIntegerKeys() and TemplatePaths::sanitizePaths(), which calls array_unique(), and … And then we have this:
[ 1 => 'EXT:test/Resources/Private/Partials/', 2 => 'EXT:news/Resources/Private/Partials/', 3 => 'EXT:eventnews/Resources/Private/Partials/' ]
So my 20 entry has gone because ActionController::resolveView() prepended the array with the default view path for my extension without checking that it already exists there and in the different order. Thus it changed my order of paths. Same happens for layout and template paths.
Skipping path to my ext does not change anything.
The right solution would be to check for the existence of the path in the confuguration inside the ActionController::resolveView(). If the path is explicitely set, do not prepend it. That’s all.
Reviews 4
- 13.4 92635[BUGFIX] Order template, partial and layout paths correctly in Extbase context
- main 92615[BUGFIX] Order template, partial and layout paths correctly in Extbase context
- main 92619[TASK] Increase test coverage for template path overrides
- 13.4 92620[TASK] Increase test coverage for template path overrides