2 namespace TYPO3\CMS\Rsaauth\Form\Element
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Form\Element\AbstractFormElement
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
19 use TYPO3\CMS\Core\Utility\MathUtility
;
20 use TYPO3\CMS\Core\Utility\StringUtility
;
23 * Generation of form element of the type rsaInput
25 class RsaInputElement
extends AbstractFormElement
28 * Default field wizards enabled for this element.
32 protected $defaultFieldWizard = [
33 'otherLanguageContent' => [
34 'renderType' => 'otherLanguageContent',
36 'defaultLanguageDifferences' => [
37 'renderType' => 'defaultLanguageDifferences',
39 'otherLanguageContent',
45 * This will render a single-line input form field, possibly with various control/validation features
47 * @return array As defined in initializeResultArray() of AbstractNode
49 public function render()
51 $fieldName = $this->data
['fieldName'];
52 $parameterArray = $this->data
['parameterArray'];
53 $resultArray = $this->initializeResultArray();
54 $resultArray['requireJsModules'] = ['TYPO3/CMS/Rsaauth/RsaEncryptionModule'];
56 $itemValue = $parameterArray['itemFormElValue'];
57 $config = $parameterArray['fieldConf']['config'];
58 $size = MathUtility
::forceIntegerInRange($config['size'] ?
: $this->defaultInputWidth
, $this->minimumInputWidth
, $this->maxInputWidth
);
59 $evalList = GeneralUtility
::trimExplode(',', $config['eval'], true);
60 $width = (int)$this->formMaxWidth($size);
62 if ($config['readOnly']) {
63 // Early return for read only fields
64 if (in_array('password', $evalList, true)) {
65 $itemValue = $itemValue ?
'*********' : '';
68 $html[] = '<div class="t3js-formengine-field-item">';
69 $html[] = '<div class="form-wizards-wrap">';
70 $html[] = '<div class="form-wizards-element">';
71 $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
72 $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>';
77 $resultArray['html'] = implode(LF
, $html);
81 // @todo: The whole eval handling is a mess and needs refactoring
82 foreach ($evalList as $func) {
83 // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
84 // @todo: keyword like "date", or a class reference. The global registration could be dropped then
85 // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
86 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
87 if (class_exists($func)) {
88 $evalObj = GeneralUtility
::makeInstance($func);
89 if (method_exists($evalObj, 'deevaluateFieldValue')) {
93 $itemValue = $evalObj->deevaluateFieldValue($_params);
95 if (method_exists($evalObj, 'returnFieldJS')) {
96 $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility
::quoteJSvalue($func) . ']'
97 . ' = function(value) {' . $evalObj->returnFieldJS() . '};';
102 $evalList = array_filter($evalList, function ($value) {
103 return $value !== 'password';
108 'id' => StringUtility
::getUniqueId('formengine-input-'),
110 'class' => implode(' ', [
115 'data-formengine-validation-rules'=> $this->getValidationDataAsJsonString($config),
116 'data-formengine-input-params' => json_encode([
117 'field' => $parameterArray['itemFormElName'],
118 'evalList' => implode(',', $evalList),
119 'is_in' => trim($config['is_in']),
121 'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
124 if (isset($config['max']) && (int)$config['max'] > 0) {
125 $attributes['maxlength'] = (int)$config['max'];
127 if (!empty($config['placeholder'])) {
128 $attributes['placeholder'] = trim($config['placeholder']);
130 if (isset($config['autocomplete'])) {
131 $attributes['autocomplete'] = empty($config['autocomplete']) ?
'new-' . $fieldName : 'on';
133 if (in_array('password', $evalList)) {
134 $attributes['type'] = 'password';
135 $attributes['value'] = $itemValue ?
'*********' : '';
136 $attributes['autocomplete'] = 'new-' . $fieldName;
139 $legacyWizards = $this->renderWizards();
140 $legacyFieldControlHtml = implode(LF
, $legacyWizards['fieldControl']);
141 $legacyFieldWizardHtml = implode(LF
, $legacyWizards['fieldWizard']);
143 $fieldInformationResult = $this->renderFieldInformation();
144 $fieldInformationHtml = $fieldInformationResult['html'];
145 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
147 $fieldControlResult = $this->renderFieldControl();
148 $fieldControlHtml = $legacyFieldControlHtml . $fieldControlResult['html'];
149 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
151 $fieldWizardResult = $this->renderFieldWizard();
152 $fieldWizardHtml = $legacyFieldWizardHtml . $fieldWizardResult['html'];
153 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
156 $html[] = '<div class="t3js-formengine-field-item">';
157 $html[] = $fieldInformationHtml;
158 $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
159 $html[] = '<div class="form-wizards-wrap">';
160 $html[] = '<div class="form-wizards-element">';
161 $html[] = '<input ' . GeneralUtility
::implodeAttributes($attributes, true) . ' />';
163 $html[] = ' type="hidden"';
164 $html[] = ' data-rsa-encryption=""';
165 $html[] = ' id="' . $parameterArray['itemFormElID'] . '_hidden"';
166 $html[] = ' name="' . $parameterArray['itemFormElName'] . '"';
167 $html[] = ' value="' . htmlspecialchars($itemValue) . '"';
170 $html[] = '<div class="form-wizards-items-aside">';
171 $html[] = '<div class="btn-group">';
172 $html[] = $fieldControlHtml;
175 $html[] = '<div class="form-wizards-items-bottom">';
176 $html[] = $fieldWizardHtml;
182 $resultArray['html'] = implode(LF
, $html);