[BUGFIX] Use sys_file as soft reference for formDefinitions 30/55830/4
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Tue, 20 Feb 2018 15:55:03 +0000 (16:55 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 20 Feb 2018 20:23:45 +0000 (21:23 +0100)
Register an embedded form definition as sys_file soft reference to show
the usage of the form definition within the file list module.

Resolves: #83502
Releases: master, 8.7
Change-Id: Ifdba760b8ebd45a9b83e97c5a20cf23ede6a74d7
Reviewed-on: https://review.typo3.org/55830
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/form/Classes/Controller/FormManagerController.php
typo3/sysext/form/Classes/Hooks/SoftReferenceParserHook.php

index 0aed1a7..15c7a41 100644 (file)
@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Messaging\AbstractMessage;
 use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Mvc\View\JsonView;
@@ -401,6 +402,9 @@ class FormManagerController extends AbstractBackendController
             throw new \InvalidArgumentException('$persistenceIdentifier must not be empty.', 1472238493);
         }
 
+        $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
+        $file = $resourceFactory->retrieveFileOrFolderObject($persistenceIdentifier);
+
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex');
         $referenceRows = $queryBuilder
             ->select('*')
@@ -408,7 +412,10 @@ class FormManagerController extends AbstractBackendController
             ->where(
                 $queryBuilder->expr()->eq('deleted', 0),
                 $queryBuilder->expr()->eq('softref_key', $queryBuilder->createNamedParameter('formPersistenceIdentifier', \PDO::PARAM_STR)),
-                $queryBuilder->expr()->eq('ref_string', $queryBuilder->createNamedParameter($persistenceIdentifier, \PDO::PARAM_STR)),
+                $queryBuilder->expr()->orX(
+                    $queryBuilder->expr()->eq('ref_string', $queryBuilder->createNamedParameter($persistenceIdentifier, \PDO::PARAM_STR)),
+                    $queryBuilder->expr()->eq('ref_uid', $queryBuilder->createNamedParameter($file->getUid(), \PDO::PARAM_INT))
+                ),
                 $queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter('tt_content', \PDO::PARAM_STR))
             )
             ->execute()
index 17d22b1..5964a61 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Form\Hooks;
  */
 
 use TYPO3\CMS\Core\Database\SoftReferenceIndex;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Register new referenced formDefinitions within a plugin as a soft reference.
@@ -43,13 +45,18 @@ class SoftReferenceParserHook extends SoftReferenceIndex
     {
         $this->tokenID_basePrefix = $table . ':' . $uid . ':' . $field . ':' . $structurePath . ':' . $spKey;
         $tokenId = $this->makeTokenID($content);
+
+        $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
+        $file = $resourceFactory->retrieveFileOrFolderObject($content);
+
         return [
             'content' => '{softref:' . $tokenId . '}',
             'elements' => [
                 $tokenId => [
                     'matchString' => $content,
                     'subst' => [
-                        'type' => 'string',
+                        'type' => 'db',
+                        'recordRef' => 'sys_file:' . $file->getUid(),
                         'tokenID' => $tokenId,
                         'tokenValue' => $content
                     ],