TYPO3 CMS  TYPO3_8-7
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 $defaultFieldWizard = [
33  'otherLanguageContent' => [
34  'renderType' => 'otherLanguageContent',
35  ],
36  'defaultLanguageDifferences' => [
37  'renderType' => 'defaultLanguageDifferences',
38  'after' => [
39  'otherLanguageContent',
40  ],
41  ],
42  ];
43 
49  public function render()
50  {
51  $fieldName = $this->data['fieldName'];
52  $parameterArray = $this->data['parameterArray'];
53  $resultArray = $this->initializeResultArray();
54  $resultArray['requireJsModules'] = ['TYPO3/CMS/Rsaauth/RsaEncryptionModule'];
55 
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);
61  $isPasswordField = in_array('password', $evalList, true);
62 
63  if ($config['readOnly']) {
64  // Early return for read only fields
65  if ($isPasswordField) {
66  $itemValue = $itemValue ? '*********' : '';
67  }
68  $html = [];
69  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
70  $html[] = '<div class="form-wizards-wrap">';
71  $html[] = '<div class="form-wizards-element">';
72  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
73  $html[] = '<input class="form-control" value="' . htmlspecialchars($itemValue) . '" type="text" disabled>';
74  $html[] = '</div>';
75  $html[] = '</div>';
76  $html[] = '</div>';
77  $html[] = '</div>';
78  $resultArray['html'] = implode(LF, $html);
79  return $resultArray;
80  }
81 
82  // @todo: The whole eval handling is a mess and needs refactoring
83  foreach ($evalList as $func) {
84  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
85  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
86  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
87  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
88  if (class_exists($func)) {
89  $evalObj = GeneralUtility::makeInstance($func);
90  if (method_exists($evalObj, 'deevaluateFieldValue')) {
91  $_params = [
92  'value' => $itemValue
93  ];
94  $itemValue = $evalObj->deevaluateFieldValue($_params);
95  }
96  if (method_exists($evalObj, 'returnFieldJS')) {
97  $resultArray['additionalJavaScriptPost'][] = 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($func) . ']'
98  . ' = function(value) {' . $evalObj->returnFieldJS() . '};';
99  }
100  }
101  }
102  }
103  $evalList = array_filter($evalList, function ($value) {
104  return $value !== 'password';
105  });
106 
107  $attributes = [
108  'type' => 'text',
109  'id' => StringUtility::getUniqueId('formengine-input-'),
110  'value' => '',
111  'class' => implode(' ', [
112  'form-control',
113  't3js-clearable',
114  'hasDefaultValue',
115  ]),
116  'data-formengine-validation-rules'=> $this->getValidationDataAsJsonString($config),
117  'data-formengine-input-params' => json_encode([
118  'field' => $parameterArray['itemFormElName'],
119  'evalList' => implode(',', $evalList),
120  'is_in' => trim($config['is_in']),
121  ]),
122  'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
123  ];
124 
125  if (isset($config['max']) && (int)$config['max'] > 0) {
126  $attributes['maxlength'] = (int)$config['max'];
127  }
128  if (!empty($config['placeholder'])) {
129  $attributes['placeholder'] = trim($config['placeholder']);
130  }
131  if (isset($config['autocomplete'])) {
132  $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
133  }
134  if ($isPasswordField) {
135  $attributes['type'] = 'password';
136  $attributes['value'] = $itemValue ? '*********' : '';
137  $attributes['autocomplete'] = 'new-' . $fieldName;
138  }
139 
140  $legacyWizards = $this->renderWizards();
141  $legacyFieldControlHtml = implode(LF, $legacyWizards['fieldControl']);
142  $legacyFieldWizardHtml = implode(LF, $legacyWizards['fieldWizard']);
143 
144  $fieldInformationResult = $this->renderFieldInformation();
145  $fieldInformationHtml = $fieldInformationResult['html'];
146  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
147 
148  $fieldControlResult = $this->renderFieldControl();
149  $fieldControlHtml = $legacyFieldControlHtml . $fieldControlResult['html'];
150  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
151 
152  $fieldWizardResult = $this->renderFieldWizard();
153  $fieldWizardHtml = $legacyFieldWizardHtml . $fieldWizardResult['html'];
154  $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
155 
156  $html = [];
157  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
158  $html[] = $fieldInformationHtml;
159  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
160  $html[] = '<div class="form-wizards-wrap">';
161  $html[] = '<div class="form-wizards-element">';
162  $html[] = '<input ' . GeneralUtility::implodeAttributes($attributes, true) . ' />';
163  $html[] = '<input';
164  $html[] = ' type="hidden"';
165  $html[] = ' data-rsa-encryption=""';
166  $html[] = ' id="' . $parameterArray['itemFormElID'] . '_hidden"';
167  $html[] = ' name="' . $parameterArray['itemFormElName'] . '"';
168  $html[] = ' value="' . htmlspecialchars($itemValue) . '"';
169  $html[] = '/>';
170  $html[] = '</div>';
171  $html[] = '<div class="form-wizards-items-aside">';
172  $html[] = '<div class="btn-group">';
173  $html[] = $fieldControlHtml;
174  $html[] = '</div>';
175  $html[] = '</div>';
176  $html[] = '<div class="form-wizards-items-bottom">';
177  $html[] = $fieldWizardHtml;
178  $html[] = '</div>';
179  $html[] = '</div>';
180  $html[] = '</div>';
181  $html[] = '</div>';
182 
183  $resultArray['html'] = implode(LF, $html);
184  return $resultArray;
185  }
186 }
static implodeAttributes(array $arr, $xhtmlSafe=false, $dontOmitBlankAttribs=false)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
renderWizards( $itemKinds=null, $wizConf=null, $table=null, $row=null, $fieldName=null, $PA=null, $itemName=null, $specConf=null, $RTE=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']