TYPO3 CMS  TYPO3_7-6
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 
22 
27 {
33  public function render()
34  {
35  $table = $this->data['tableName'];
36  $fieldName = $this->data['fieldName'];
37  $row = $this->data['databaseRow'];
38  $parameterArray = $this->data['parameterArray'];
39  $resultArray = $this->initializeResultArray();
40  $resultArray['requireJsModules'] = ['TYPO3/CMS/Rsaauth/RsaEncryptionModule'];
41 
42  $config = $parameterArray['fieldConf']['config'];
43  $specConf = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
44  $size = MathUtility::forceIntegerInRange($config['size'] ?: $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth);
45  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
46  $classes = [];
47  $attributes = [
48  'type' => 'text',
49  'value' => '',
50  ];
51 
52  if ($config['readOnly']) {
53  $itemFormElValue = $parameterArray['itemFormElValue'];
54  $options = $this->data;
55  $options['parameterArray'] = [
56  'fieldConf' => [
57  'config' => $config,
58  ],
59  'itemFormElValue' => $itemFormElValue,
60  ];
61  $options['renderType'] = 'none';
62  return $this->nodeFactory->create($options)->render();
63  }
64 
65  // @todo: The whole eval handling is a mess and needs refactoring
66  foreach ($evalList as $func) {
67  switch ($func) {
68  case 'required':
69  $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString(['required' => true]);
70  break;
71  case 'password':
72  $attributes['type'] = 'password';
73  $attributes['value'] = $parameterArray['itemFormElValue'] ? '*********' : '';
74  $attributes['autocomplete'] = 'new-' . $fieldName;
75  break;
76  default:
77  // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
78  // @todo: keyword like "date", or a class reference. The global registration could be dropped then
79  // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
80  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
81  if (class_exists($func)) {
82  $evalObj = GeneralUtility::makeInstance($func);
83  if (method_exists($evalObj, 'deevaluateFieldValue')) {
84  $_params = [
85  'value' => $parameterArray['itemFormElValue']
86  ];
87  $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
88  }
89  }
90  }
91  }
92  }
93  $evalList = array_filter($evalList, function ($value) {
94  return $value !== 'password';
95  });
96 
97  $paramsList = [
98  'field' => $parameterArray['itemFormElName'],
99  'evalList' => implode(',', $evalList),
100  'is_in' => trim($config['is_in']),
101  ];
102  // set classes
103  $classes[] = 'form-control';
104  $classes[] = 't3js-clearable';
105  $classes[] = 'hasDefaultValue';
106 
107  // calculate attributes
108  $attributes['data-formengine-validation-rules'] = $this->getValidationDataAsJsonString($config);
109  $attributes['data-formengine-input-params'] = json_encode($paramsList);
110  $attributes['data-formengine-input-name'] = htmlspecialchars($parameterArray['itemFormElName']);
111  $attributes['id'] = StringUtility::getUniqueId('formengine-input-');
112  if (isset($config['max']) && (int)$config['max'] > 0) {
113  $attributes['maxlength'] = (int)$config['max'];
114  }
115  if (!empty($classes)) {
116  $attributes['class'] = implode(' ', $classes);
117  }
118  if (isset($config['max']) && (int)$config['max'] > 0) {
119  $attributes['maxlength'] = (int)$config['max'];
120  }
121 
122  // This is the EDITABLE form field.
123  if (!empty($config['placeholder'])) {
124  $attributes['placeholder'] = trim($config['placeholder']);
125  }
126 
127  if (isset($config['autocomplete'])) {
128  $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
129  }
130 
131  // Build the attribute string
132  $attributeString = '';
133  foreach ($attributes as $attributeName => $attributeValue) {
134  $attributeString .= ' ' . $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
135  }
136 
137  $html = '
138  <input'
139  . $attributeString
140  . $parameterArray['onFocus'] . ' />';
141 
142  // This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
143  $html .= '<input type="hidden" data-rsa-encryption="" id="' . $parameterArray['itemFormElID'] . '_hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
144 
145  // Going through all custom evaluations configured for this field
146  // @todo: Similar to above code!
147  foreach ($evalList as $evalData) {
148  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData])) {
149  if (class_exists($evalData)) {
150  $evalObj = GeneralUtility::makeInstance($evalData);
151  if (method_exists($evalObj, 'returnFieldJS')) {
152  $resultArray['extJSCODE'] .= LF . 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '}';
153  }
154  }
155  }
156  }
157 
158  // Wrap a wizard around the item?
159  $html = $this->renderWizards(
160  [$html],
161  $config['wizards'],
162  $table,
163  $row,
164  $fieldName,
165  $parameterArray,
166  $parameterArray['itemFormElName'],
167  $specConf
168  );
169 
170  // Add a wrapper to remain maximum width
171  $width = (int)$this->formMaxWidth($size);
172  $html = '<div class="form-control-wrap"' . ($width ? ' style="max-width: ' . $width . 'px"' : '') . '>' . $html . '</div>';
173  $resultArray['html'] = $html;
174  return $resultArray;
175  }
176 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getSpecConfParts($defaultExtrasString, $_='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']