[BUGFIX] Correct namespace for RichTextElement
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Form / Element / RichTextElement.php
1 <?php
2 namespace TYPO3\CMS\Rtehtmlarea\Form\Element;
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\Backend\Form\Element\AbstractFormElement;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Utility\MathUtility;
21 use TYPO3\CMS\Backend\Form\FormEngine;
22 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23 use TYPO3\CMS\Backend\Form\NodeFactory;
24
25 /**
26 * Render rich text editor in FormEngine
27 */
28 class RichTextElement extends AbstractFormElement {
29
30 /**
31 * This will render a <textarea> OR RTE area form field,
32 * possibly with various control/validation features
33 *
34 * @return array As defined in initializeResultArray() of AbstractNode
35 */
36 public function render() {
37 $table = $this->globalOptions['table'];
38 $fieldName = $this->globalOptions['fieldName'];
39 $row = $this->globalOptions['databaseRow'];
40 $parameterArray = $this->globalOptions['parameterArray'];
41 $resultArray = $this->initializeResultArray();
42 $backendUser = $this->getBackendUserAuthentication();
43
44 $evalList = GeneralUtility::trimExplode(',', $parameterArray['fieldConf']['config']['eval'], TRUE);
45 if (in_array('required', $evalList, TRUE)) {
46 $resultArray['requiredFields'][$table . '_' . $row['uid'] . '_' . $fieldName] = $parameterArray['itemFormElName'];
47 $tabAndInlineStack = $this->globalOptions['tabAndInlineStack'];
48 if (!empty($tabAndInlineStack) && preg_match('/^(.+\\])\\[(\\w+)\\]$/', $parameterArray['itemFormElName'], $match)) {
49 array_shift($match);
50 $resultArray['requiredNested'][$parameterArray['itemFormElName']] = array(
51 'parts' => $match,
52 'level' => $tabAndInlineStack,
53 );
54 }
55 }
56
57 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
58 $specialConfiguration = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
59 // Setting up the altItem form field, which is a hidden field containing the value
60 $altItem = '<input type="hidden" name="' . htmlspecialchars($parameterArray['itemFormElName']) . '" value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
61
62 BackendUtility::fixVersioningPid($table, $row);
63 list($recordPid, $tsConfigPid) = BackendUtility::getTSCpidCached($table, $row['uid'], $row['pid']);
64
65 // If the pid-value is not negative (that is, a pid could NOT be fetched)
66 $rteSetup = $backendUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($recordPid));
67 $rteTcaTypeValue = BackendUtility::getTCAtypeValue($table, $row);
68 $rteSetupConfiguration = BackendUtility::RTEsetup($rteSetup['properties'], $table, $fieldName, $rteTcaTypeValue);
69
70 // Get RTE object, draw form and set flag:
71 $rteObject = BackendUtility::RTEgetObj();
72 $dummyFormEngine = new FormEngine();
73 $rteResult = $rteObject->drawRTE(
74 $dummyFormEngine,
75 $table,
76 $fieldName,
77 $row,
78 $parameterArray,
79 $specialConfiguration,
80 $rteSetupConfiguration,
81 $rteTcaTypeValue,
82 '',
83 $tsConfigPid,
84 $this->globalOptions,
85 $this->initializeResultArray()
86 );
87 // This is a compat layer for "other" RTE's: If the result is not an array, it is the html string,
88 // otherwise it is a structure similar to our casual return array
89 // @todo: This interface needs a full re-definition, RTE should probably be its own type in the
90 // @todo: end, and other RTE implementations could then just override this.
91 if (is_array($rteResult)) {
92 $html = $rteResult['html'];
93 $rteResult['html'] = '';
94 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $rteResult);
95 } else {
96 $html = $rteResult;
97 }
98
99 // Wizard
100 $html = $this->renderWizards(
101 array($html, $altItem),
102 $parameterArray['fieldConf']['config']['wizards'],
103 $table,
104 $row,
105 $fieldName,
106 $parameterArray,
107 $parameterArray['itemFormElName'],
108 $specialConfiguration,
109 TRUE
110 );
111
112 $resultArray['html'] = $html;
113 return $resultArray;
114 }
115
116 /**
117 * @return BackendUserAuthentication
118 */
119 protected function getBackendUserAuthentication() {
120 return $GLOBALS['BE_USER'];
121 }
122
123 }