[TASK] Streamline usage of form framework icons
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Hooks / SoftReferenceParserHook.php
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
17 use TYPO3\CMS\Core\Database\SoftReferenceIndex;
18
19 /**
20 * Register new referenced formDefinitions within a plugin as a soft reference.
21 *
22 * This is used in BE to track how often a specific form is used in a content
23 * element. The number is shown in the form module "Manage forms".
24 *
25 * Scope: backend
26 * @internal
27 */
28 class SoftReferenceParserHook extends SoftReferenceIndex
29 {
30 /**
31 * Main function through which all processing happens
32 *
33 * @param string $table Database table name
34 * @param string $field Field name for which processing occurs
35 * @param int $uid UID of the record
36 * @param string $content The content/value of the field
37 * @param string $spKey The softlink parser key. This is only interesting if more than one parser is grouped in the same class. That is the case with this parser.
38 * @param array $spParams Parameters of the softlink parser. Basically this is the content inside optional []-brackets after the softref keys. Parameters are exploded by ";
39 * @param string $structurePath If running from inside a FlexForm structure, this is the path of the tag.
40 * @return array Result array on positive matches, see description above. Otherwise FALSE
41 */
42 public function findRef($table, $field, $uid, $content, $spKey, $spParams, $structurePath = '')
43 {
44 $this->tokenID_basePrefix = $table . ':' . $uid . ':' . $field . ':' . $structurePath . ':' . $spKey;
45 $tokenId = $this->makeTokenID($content);
46 return [
47 'content' => '{softref:' . $tokenId . '}',
48 'elements' => [
49 $tokenId => [
50 'matchString' => $content,
51 'subst' => [
52 'type' => 'string',
53 'tokenID' => $tokenId,
54 'tokenValue' => $content
55 ],
56 ]
57 ]
58 ];
59 }
60 }