‪TYPO3CMS  9.5
RsaInputElement.php
Go to the documentation of this file.
1 <?php
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 
21 
26 {
32  protected ‪$defaultFieldInformation = [
33  'tcaDescription' => [
34  'renderType' => 'tcaDescription',
35  ],
36  ];
37 
43  protected ‪$defaultFieldWizard = [
44  'otherLanguageContent' => [
45  'renderType' => 'otherLanguageContent',
46  ],
47  'defaultLanguageDifferences' => [
48  'renderType' => 'defaultLanguageDifferences',
49  'after' => [
50  'otherLanguageContent',
51  ],
52  ],
53  ];
54 
60  public function ‪render()
61  {
62  $fieldName = $this->data['fieldName'];
63  $parameterArray = $this->data['parameterArray'];
64  $resultArray = $this->‪initializeResultArray();
65  $resultArray['requireJsModules'] = ['TYPO3/CMS/Rsaauth/RsaEncryptionModule'];
66 
67  $itemValue = $parameterArray['itemFormElValue'];
68  $config = $parameterArray['fieldConf']['config'];
69  $size = ‪MathUtility::forceIntegerInRange($config['size'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth);
70  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
71  $width = (int)$this->‪formMaxWidth($size);
72  $isPasswordField = in_array('password', $evalList, true);
73 
74  $fieldInformationResult = $this->‪renderFieldInformation();
75  $fieldInformationHtml = $fieldInformationResult['html'];
76  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
77 
78  if ($config['readOnly']) {
79  // Early return for read only fields
80  if ($isPasswordField) {
81  $itemValue = $itemValue ? '*********' : '';
82  }
83  $html = [];
84  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
85  $html[] = $fieldInformationHtml;
86  $html[] = '<div class="form-wizards-wrap">';
87  $html[] = '<div class="form-wizards-element">';
88  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
89  $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>';
90  $html[] = '</div>';
91  $html[] = '</div>';
92  $html[] = '</div>';
93  $html[] = '</div>';
94  $resultArray['html'] = implode(LF, $html);
95  return $resultArray;
96  }
97 
98  // @todo: The whole eval handling is a mess and needs refactoring
99  foreach ($evalList as $func) {
100  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
101  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
102  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
103  if (isset(‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
104  if (class_exists($func)) {
105  $evalObj = GeneralUtility::makeInstance($func);
106  if (method_exists($evalObj, 'deevaluateFieldValue')) {
107  $_params = [
108  'value' => $itemValue
109  ];
110  $itemValue = $evalObj->deevaluateFieldValue($_params);
111  }
112  if (method_exists($evalObj, 'returnFieldJS')) {
113  $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($func) . ']'
114  . ' = function(value) {' . $evalObj->returnFieldJS() . '};';
115  }
116  }
117  }
118  }
119  $evalList = array_filter($evalList, function ($value) {
120  return $value !== 'password';
121  });
122 
123  $attributes = [
124  'type' => 'text',
125  'id' => ‪StringUtility::getUniqueId('formengine-input-'),
126  'value' => '',
127  'class' => implode(' ', [
128  'form-control',
129  't3js-clearable',
130  'hasDefaultValue',
131  ]),
132  'data-formengine-validation-rules'=> $this->‪getValidationDataAsJsonString($config),
133  'data-formengine-input-params' => json_encode([
134  'field' => $parameterArray['itemFormElName'],
135  'evalList' => implode(',', $evalList),
136  'is_in' => trim($config['is_in']),
137  ]),
138  'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
139  ];
140 
141  if (isset($config['max']) && (int)$config['max'] > 0) {
142  $attributes['maxlength'] = (int)$config['max'];
143  }
144  if (!empty($config['placeholder'])) {
145  $attributes['placeholder'] = trim($config['placeholder']);
146  }
147  if (isset($config['autocomplete'])) {
148  $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
149  }
150  if ($isPasswordField) {
151  $attributes['type'] = 'password';
152  $attributes['value'] = $itemValue ? '*********' : '';
153  $attributes['autocomplete'] = 'new-' . $fieldName;
154  }
155 
156  $fieldControlResult = $this->‪renderFieldControl();
157  $fieldControlHtml = $fieldControlResult['html'];
158  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
159 
160  $fieldWizardResult = $this->‪renderFieldWizard();
161  $fieldWizardHtml = $fieldWizardResult['html'];
162  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
163 
164  $html = [];
165  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
166  $html[] = $fieldInformationHtml;
167  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
168  $html[] = '<div class="form-wizards-wrap">';
169  $html[] = '<div class="form-wizards-element">';
170  $html[] = '<input ' . GeneralUtility::implodeAttributes($attributes, true) . ' />';
171  $html[] = '<input';
172  $html[] = ' type="hidden"';
173  $html[] = ' data-rsa-encryption=""';
174  $html[] = ' id="' . $parameterArray['itemFormElID'] . '_hidden"';
175  $html[] = ' name="' . $parameterArray['itemFormElName'] . '"';
176  $html[] = ' value="' . htmlspecialchars($itemValue) . '"';
177  $html[] = '/>';
178  $html[] = '</div>';
179  if (!empty($fieldControlHtml)) {
180  $html[] = '<div class="form-wizards-items-aside">';
181  $html[] = '<div class="btn-group">';
182  $html[] = $fieldControlHtml;
183  $html[] = '</div>';
184  $html[] = '</div>';
185  }
186  if (!empty($fieldWizardHtml)) {
187  $html[] = '<div class="form-wizards-items-bottom">';
188  $html[] = $fieldWizardHtml;
189  $html[] = '</div>';
190  }
191  $html[] = '</div>';
192  $html[] = '</div>';
193  $html[] = '</div>';
194 
195  $resultArray['html'] = implode(LF, $html);
196  return $resultArray;
197  }
198 }
‪TYPO3\CMS\Rsaauth\Form\Element\RsaInputElement\render
‪array render()
Definition: RsaInputElement.php:58
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:71
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:115
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
‪TYPO3\CMS\Rsaauth\Form\Element\RsaInputElement
Definition: RsaInputElement.php:26
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:31
‪TYPO3\CMS\Rsaauth\Form\Element\RsaInputElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: RsaInputElement.php:41
‪TYPO3\CMS\Rsaauth\Form\Element\RsaInputElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: RsaInputElement.php:31
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪string getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:153
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldControl
‪array renderFieldControl()
Definition: AbstractFormElement.php:87
‪TYPO3\CMS\Rsaauth\Form\Element
Definition: RsaInputElement.php:2
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\formMaxWidth
‪int formMaxWidth($size=48)
Definition: AbstractFormElement.php:297
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:21
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:103