Skip to content

Commit d1b436e

Browse files
committed
[BUGFIX] Abuse of storage 0 for extension resources
This patch makes sure the virtual storage 0 is not longer abused by the StaticFilesProcessor. Therefor the StaticFilesProcessor now returns URIs of the provided files and not longer FILE objects. All `EXT:` references are now properly resolved through `PathUtility::getPublicResourceWebPath()` if available (TYPO3 11.4.0 and higher) or by providing an absolute path to `PathUtility::getAbsoluteWebPath`. FAL resources are resolved using `PathUtility::getAbsoluteWebPath` also by providing an absolute path. The new behavior is disabled by default and can be enabled by setting "compatibilityMode" to "false".
1 parent 5bde1c5 commit d1b436e

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

Build/phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Call to function method_exists\\(\\) with 'TYPO3\\\\\\\\CMS\\\\\\\\Core\\\\\\\\Utility\\\\\\\\PathUtility' and 'getPublicResourceWe…' will always evaluate to true\\.$#"
5+
count: 1
6+
path: ../Classes/DataProcessing/StaticFilesProcessor.php
7+
8+
-
9+
message: "#^Call to an undefined static method TYPO3\\CMS\\Core\\Utility\\PathUtility::getPublicResourceWebPath\\(\\).$#"
10+
count: 1
11+
path: ../Classes/DataProcessing/StaticFilesProcessor.php
12+
313
-
414
message:
515
"""

Classes/DataProcessing/StaticFilesProcessor.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
use TYPO3\CMS\Core\Resource\ResourceFactory;
1313
use TYPO3\CMS\Core\Utility\GeneralUtility;
14+
use TYPO3\CMS\Core\Utility\PathUtility;
1415
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1516
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
1617

1718
/**
18-
* This processor generates a set of file objects.
19+
* This processor generates a set of file objects (deprecated) or URIs.
1920
*
2021
* 10 = BK2K\BootstrapPackage\DataProcessing\StaticFilesProcessor
2122
* 10 {
@@ -24,6 +25,7 @@
2425
* 1 = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-1.png
2526
* circle = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-circle.png
2627
* }
28+
* compatibilityMode = false
2729
* as = staticFiles
2830
* }
2931
*/
@@ -55,15 +57,31 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
5557
}
5658
}
5759

58-
// Get file objects
60+
// Get file objects (deprecated) or URI for each file
5961
$images = [];
6062
if (count($files) !== 0) {
61-
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
63+
// @todo: compat fallback, will be removed with v13
64+
$resourceFactory = null;
65+
if ($this->isCompatibilityMode($processorConfiguration)) {
66+
trigger_error(
67+
'The resolvement to FILE objects is deprecated and will stop working in Bootstrap Package 13.0. Change your Fluid templates properly and set "compatibilityMode" to "false".',
68+
E_USER_DEPRECATED
69+
);
70+
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
71+
}
72+
6273
foreach ($files as $key => $file) {
6374
$absFilename = GeneralUtility::getFileAbsFileName($file);
6475
if (file_exists($absFilename)) {
65-
// Do not use absolute file name to ensure correct path resolution from ResourceFactory.
66-
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($file);
76+
if ($resourceFactory instanceof ResourceFactory) {
77+
// @todo: compat fallback, will be removed with v13
78+
// Do not use absolute file name to ensure correct path resolution from ResourceFactory.
79+
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($file);
80+
} elseif (str_starts_with($file, 'EXT:') && method_exists(PathUtility::class, 'getPublicResourceWebPath')) {
81+
$images[$key] = PathUtility::getPublicResourceWebPath($file);
82+
} else {
83+
$images[$key] = PathUtility::getAbsoluteWebPath($absFilename);
84+
}
6785
}
6886
}
6987
}
@@ -78,4 +96,13 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
7896

7997
return $processedData;
8098
}
99+
100+
/**
101+
* @param array $processorConfiguration The configuration of this processor
102+
* @return bool
103+
*/
104+
private function isCompatibilityMode(array $processorConfiguration)
105+
{
106+
return !isset($processorConfiguration['compatibilityMode']) || $processorConfiguration['compatibilityMode'] !== 'false';
107+
}
81108
}

Configuration/TypoScript/setup.typoscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ page {
236236
normal = {$page.logo.file}
237237
inverted = {$page.logo.fileInverted}
238238
}
239+
compatibilityMode = false
239240
as = logo
240241
}
241242
}

Resources/Private/Partials/Page/Header/Logo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<f:link.page pageUid="{rootPage}" class="navbar-brand navbar-brand-{f:if(condition: logo.normal, then: 'image', else: 'text')}" title="{settings.logo.linktitle}">
33
<f:if condition="{logo.normal}">
44
<f:then>
5-
<img class="navbar-brand-logo-normal" src="{f:uri.image(image: logo.normal)}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
5+
<img class="navbar-brand-logo-normal" src="{logo.normal}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
66
<f:if condition="{logo.inverted}">
7-
<img class="navbar-brand-logo-inverted" src="{f:uri.image(image: logo.inverted)}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
7+
<img class="navbar-brand-logo-inverted" src="{logo.inverted}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
88
</f:if>
99
</f:then>
1010
<f:else>

0 commit comments

Comments
 (0)