[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / TcaText.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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
18 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
19 use TYPO3\CMS\Core\Configuration\Richtext;
20 use TYPO3\CMS\Core\Html\RteHtmlParser;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Resolve databaseRow field content for type=text, especially handle
25 * richtext transformations "from db to rte"
26 */
27 class TcaText implements FormDataProviderInterface
28 {
29 /**
30 * Handle text field content, especially richtext transformation
31 *
32 * @param array $result Given result array
33 * @return array Modified result array
34 */
35 public function addData(array $result)
36 {
37 foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
38 if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'text') {
39 continue;
40 }
41
42 if (isset($fieldConfig['config']['enableRichtext']) && (bool)$fieldConfig['config']['enableRichtext'] === true) {
43 $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
44 $richtextConfiguration = $richtextConfigurationProvider->getConfiguration(
45 $result['tableName'],
46 $fieldName,
47 $result['effectivePid'],
48 (string)$result['recordTypeValue'],
49 $fieldConfig['config']
50 );
51 // Add final resolved configuration to TCA array
52 $result['processedTca']['columns'][$fieldName]['config']['richtextConfiguration'] = $richtextConfiguration;
53
54 // If eval=null is set for field, value might be null ... don't transform anything in this case.
55 if ($result['databaseRow'][$fieldName] !== null) {
56 // Process "from-db-to-rte" on current value
57 $parseHTML = GeneralUtility::makeInstance(RteHtmlParser::class);
58 $parseHTML->init($result['tableName'] . ':' . $fieldName, $result['effectivePid']);
59 $result['databaseRow'][$fieldName] = $parseHTML->RTE_transform(
60 $result['databaseRow'][$fieldName],
61 [],
62 'rte',
63 $richtextConfiguration
64 );
65 }
66 }
67 }
68
69 return $result;
70 }
71 }