TYPO3 CMS  TYPO3_8-7
SoftReferenceParserHook.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Hooks;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
31 {
44  public function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '')
45  {
46  $this->tokenID_basePrefix = $table . ':' . $uid . ':' . $field . ':' . $structurePath . ':' . $spKey;
47  $tokenId = $this->makeTokenID($content);
48 
49  $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
50  try {
51  $file = $resourceFactory->retrieveFileOrFolderObject($content);
52  } catch (\Exception $e) {
53  // Top level catch to ensure useful following exception handling, because FAL throws top level exceptions.
54  // TYPO3\CMS\Core\Database\ReferenceIndex::getRelations() will check the return value of this hook with is_array()
55  // so we return false to tell getRelations() to do nothing.
56  return false;
57  }
58 
59  return [
60  'content' => '{softref:' . $tokenId . '}',
61  'elements' => [
62  $tokenId => [
63  'matchString' => $content,
64  'subst' => [
65  'type' => 'db',
66  'recordRef' => 'sys_file:' . $file->getUid(),
67  'tokenID' => $tokenId,
68  'tokenValue' => $content
69  ],
70  ]
71  ]
72  ];
73  }
74 }
static makeInstance($className,... $constructorArguments)
findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath='')