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