[BUGFIX] Fix PHP error in SoftReferenceParserHook for missing form definitions 14/62314/3
authorStephan Großberndt <stephan.grossberndt@typo3.org>
Wed, 13 Nov 2019 09:50:28 +0000 (10:50 +0100)
committerRalf Zimmermann <ralf.zimmermann@tritum.de>
Thu, 21 Nov 2019 16:13:08 +0000 (17:13 +0100)
This patch adds a safe guard to make sure the `$file` object is not null
on trying to update the soft reference. This is necessary as
`ResourceFactory->retrieveFileOrFolderObject()` returns null instead of
throwing an exception in several cases (e.g. missing form definition
located in an extension).

Resolves: #89665
Releases: master, 9.5
Change-Id: I09537ddb5a4e9083992ce0fb321f4d81cd279ccf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62314
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Ralf Zimmermann <ralf.zimmermann@tritum.de>
typo3/sysext/form/Classes/Hooks/SoftReferenceParserHook.php

index 728e124..932eb94 100644 (file)
@@ -47,6 +47,7 @@ class SoftReferenceParserHook extends SoftReferenceIndex
         $tokenId = $this->makeTokenID($content);
 
         $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
+
         try {
             $file = $resourceFactory->retrieveFileOrFolderObject($content);
         } catch (\Exception $e) {
@@ -56,6 +57,10 @@ class SoftReferenceParserHook extends SoftReferenceIndex
             return false;
         }
 
+        if ($file === null) {
+            return false;
+        }
+
         return [
             'content' => '{softref:' . $tokenId . '}',
             'elements' => [