‪TYPO3CMS  9.5
SoftReferenceParserHook.php
Go to the documentation of this file.
1 <?php
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 
51  try {
52  $file = $resourceFactory->retrieveFileOrFolderObject($content);
53  } catch (\‪Exception $e) {
54  // Top level catch to ensure useful following exception handling, because FAL throws top level exceptions.
55  // TYPO3\CMS\Core\Database\ReferenceIndex::getRelations() will check the return value of this hook with is_array()
56  // so we return false to tell getRelations() to do nothing.
57  return false;
58  }
59 
60  if ($file === null) {
61  return false;
62  }
63 
64  return [
65  'content' => '{softref:' . $tokenId . '}',
66  'elements' => [
67  $tokenId => [
68  'matchString' => $content,
69  'subst' => [
70  'type' => 'db',
71  'recordRef' => 'sys_file:' . $file->getUid(),
72  'tokenID' => $tokenId,
73  'tokenValue' => $content
74  ],
75  ]
76  ]
77  ];
78  }
79 }
‪TYPO3\CMS\Form\Hooks\SoftReferenceParserHook
Definition: SoftReferenceParserHook.php:31
‪TYPO3\CMS\Core\Database\SoftReferenceIndex\makeTokenID
‪string makeTokenID($index='')
Definition: SoftReferenceIndex.php:699
‪TYPO3\CMS\Form\Hooks
Definition: DataStructureIdentifierHook.php:3
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Form\Hooks\SoftReferenceParserHook\findRef
‪array bool findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath='')
Definition: SoftReferenceParserHook.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Database\SoftReferenceIndex
Definition: SoftReferenceIndex.php:80