setTokenIdBasePrefix($table, (string)$uid, $field, $structurePath); $tokenId = $this->makeTokenID($content); // Handle extension paths (EXT:extension_key/...) if (PathUtility::isExtensionPath($content)) { return $this->createResultForExtensionReference($content, $tokenId); } // Handle numeric database identifiers (uid) if (MathUtility::canBeInterpretedAsInteger($content)) { return $this->createResultForDatabaseReference($content, $tokenId); } // Handle file storage identifiers (storage:/path) try { $file = $this->resourceFactory->retrieveFileOrFolderObject($content); } catch (\Exception $e) { // Top level catch to ensure useful following exception handling, because FAL throws top level exceptions. // TYPO3\CMS\Core\Database\ReferenceIndex::getRelations() will check the return value of this hook with is_array() // so we return null to tell getRelations() to do nothing. return SoftReferenceParserResult::createWithoutMatches(); } if ($file === null) { return SoftReferenceParserResult::createWithoutMatches(); } return SoftReferenceParserResult::create('{softref:' . $tokenId . '}', [ $tokenId => [ 'matchString' => $content, 'subst' => [ 'type' => 'db', 'recordRef' => 'sys_file:' . $file->getUid(), 'tokenID' => $tokenId, 'tokenValue' => $content, ], ], ]); } private function createResultForExtensionReference(string $extensionReference, string $tokenId): SoftReferenceParserResult { return SoftReferenceParserResult::create('{softref:' . $tokenId . '}', [ $tokenId => [ 'matchString' => $extensionReference, 'subst' => [ 'type' => 'string', 'tokenID' => $tokenId, 'tokenValue' => $extensionReference, ], ], ]); } /** * Create soft reference result for database identifiers (numeric uid) * These are stored as db references in sys_refindex for tracking usage */ private function createResultForDatabaseReference(string $databaseReference, string $tokenId): SoftReferenceParserResult { return SoftReferenceParserResult::create('{softref:' . $tokenId . '}', [ $tokenId => [ 'matchString' => $databaseReference, 'subst' => [ 'type' => 'db', 'recordRef' => FormDefinitionRepository::TABLE_NAME . ':' . $databaseReference, 'tokenID' => $tokenId, 'tokenValue' => $databaseReference, ], ], ]); } }