‪TYPO3CMS  ‪main
FormPersistenceIdentifierSoftReferenceParser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 
36 {
37  public function ‪parse(string $table, string $field, int ‪$uid, string $content, string $structurePath = ''): ‪SoftReferenceParserResult
38  {
39  $this->‪setTokenIdBasePrefix($table, (string)‪$uid, $field, $structurePath);
40  $tokenId = $this->‪makeTokenID($content);
41 
42  if (‪PathUtility::isExtensionPath($content)) {
43  return $this->‪createResultForExtensionReference($content, $tokenId);
44  }
45  try {
46  $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
47  $file = $resourceFactory->retrieveFileOrFolderObject($content);
48  } catch (\‪Exception $e) {
49  // Top level catch to ensure useful following exception handling, because FAL throws top level exceptions.
50  // TYPO3\CMS\Core\Database\ReferenceIndex::getRelations() will check the return value of this hook with is_array()
51  // so we return null to tell getRelations() to do nothing.
53  }
54 
55  if ($file === null) {
57  }
58 
59  return ‪SoftReferenceParserResult::create('{softref:' . $tokenId . '}', [
60  $tokenId => [
61  'matchString' => $content,
62  'subst' => [
63  'type' => 'db',
64  'recordRef' => 'sys_file:' . $file->getUid(),
65  'tokenID' => $tokenId,
66  'tokenValue' => $content,
67  ],
68  ],
69  ]);
70  }
71 
72  private function ‪createResultForExtensionReference(string $extensionReference, string $tokenId): ‪SoftReferenceParserResult
73  {
74  return ‪SoftReferenceParserResult::create('{softref:' . $tokenId . '}', [
75  $tokenId => [
76  'matchString' => $extensionReference,
77  'subst' => [
78  'type' => 'string',
79  'tokenID' => $tokenId,
80  'tokenValue' => $extensionReference,
81  ],
82  ],
83  ]);
84  }
85 }
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser\setTokenIdBasePrefix
‪setTokenIdBasePrefix(string $table, string $uid, string $field, string $structurePath)
Definition: AbstractSoftReferenceParser.php:55
‪TYPO3\CMS\Form\SoftReference\FormPersistenceIdentifierSoftReferenceParser\createResultForExtensionReference
‪createResultForExtensionReference(string $extensionReference, string $tokenId)
Definition: FormPersistenceIdentifierSoftReferenceParser.php:72
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:117
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult\create
‪static create(string $content, array $elements)
Definition: SoftReferenceParserResult.php:48
‪TYPO3\CMS\Form\SoftReference\FormPersistenceIdentifierSoftReferenceParser\parse
‪parse(string $table, string $field, int $uid, string $content, string $structurePath='')
Definition: FormPersistenceIdentifierSoftReferenceParser.php:37
‪TYPO3\CMS\Form\SoftReference\FormPersistenceIdentifierSoftReferenceParser
Definition: FormPersistenceIdentifierSoftReferenceParser.php:36
‪TYPO3\CMS\Form\Exception
Definition: Exception.php:25
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult\createWithoutMatches
‪static createWithoutMatches()
Definition: SoftReferenceParserResult.php:62
‪TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserResult
Definition: SoftReferenceParserResult.php:43
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Form\SoftReference
Definition: FormPersistenceIdentifierSoftReferenceParser.php:18
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser\makeTokenID
‪string makeTokenID(string $index='')
Definition: AbstractSoftReferenceParser.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\DataHandling\SoftReference\AbstractSoftReferenceParser
Definition: AbstractSoftReferenceParser.php:24