‪TYPO3CMS  ‪main
EmailElement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
28 {
34  protected ‪$defaultFieldInformation = [
35  'tcaDescription' => [
36  'renderType' => 'tcaDescription',
37  ],
38  ];
39 
45  protected ‪$defaultFieldWizard = [
46  'localizationStateSelector' => [
47  'renderType' => 'localizationStateSelector',
48  ],
49  'otherLanguageContent' => [
50  'renderType' => 'otherLanguageContent',
51  'after' => [
52  'localizationStateSelector',
53  ],
54  ],
55  'defaultLanguageDifferences' => [
56  'renderType' => 'defaultLanguageDifferences',
57  'after' => [
58  'otherLanguageContent',
59  ],
60  ],
61  ];
62 
68  public function ‪render(): array
69  {
70  $table = $this->data['tableName'];
71  $fieldName = $this->data['fieldName'];
72  $parameterArray = $this->data['parameterArray'];
73  $resultArray = $this->‪initializeResultArray();
74  $config = $parameterArray['fieldConf']['config'];
75 
76  $itemValue = $parameterArray['itemFormElValue'];
77  $width = $this->‪formMaxWidth(
78  ‪MathUtility::forceIntegerInRange($config['size'] ?? $this->defaultInputWidth, $this->minimumInputWidth, $this->maxInputWidth)
79  );
80  $fieldId = ‪StringUtility::getUniqueId('formengine-input-');
81  $renderedLabel = $this->‪renderLabel($fieldId);
82 
83  $fieldInformationResult = $this->‪renderFieldInformation();
84  $fieldInformationHtml = $fieldInformationResult['html'];
85  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
86 
87  if ($config['readOnly'] ?? false) {
88  $html = [];
89  $html[] = $renderedLabel;
90  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
91  $html[] = $fieldInformationHtml;
92  $html[] = '<div class="form-wizards-wrap">';
93  $html[] = '<div class="form-wizards-element">';
94  $html[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
95  $html[] = '<input class="form-control" id="' . htmlspecialchars($fieldId) . '" value="' . htmlspecialchars((string)$itemValue) . '" type="text" disabled>';
96  $html[] = '</div>';
97  $html[] = '</div>';
98  $html[] = '</div>';
99  $html[] = '</div>';
100  $resultArray['html'] = implode(LF, $html);
101  return $resultArray;
102  }
103 
104  $languageService = $this->‪getLanguageService();
105  $itemName = (string)$parameterArray['itemFormElName'];
106 
107  // Get filtered eval list, while always adding "trim"
108  $evalList = array_merge(array_filter(
109  ‪GeneralUtility::trimExplode(',', $config['eval'] ?? '', true),
110  static fn(string $value): bool => in_array($value, ['unique', 'uniqueInPid'], true)
111  ), ['trim']);
112 
113  if ($config['nullable'] ?? false) {
114  $evalList[] = 'null';
115  }
116 
117  $attributes = [
118  'value' => '',
119  'id' => $fieldId,
120  'maxlength' => '254',
121  'class' => implode(' ', [
122  'form-control',
123  'form-control-clearable',
124  't3js-clearable',
125  'hasDefaultValue',
126  ]),
127  'data-formengine-validation-rules' => $this->‪getValidationDataAsJsonString($config),
128  'data-formengine-input-params' => (string)json_encode([
129  'field' => $itemName,
130  'evalList' => implode(',', $evalList),
131  ], JSON_THROW_ON_ERROR),
132  'data-formengine-input-name' => $itemName,
133  ];
134 
135  if (!empty($config['placeholder'])) {
136  $attributes['placeholder'] = trim($config['placeholder']);
137  }
138  if (isset($config['autocomplete'])) {
139  $attributes['autocomplete'] = empty($config['autocomplete']) ? 'new-' . $fieldName : 'on';
140  }
141 
142  $fieldControlResult = $this->‪renderFieldControl();
143  $fieldControlHtml = $fieldControlResult['html'];
144  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false);
145 
146  $fieldWizardResult = $this->‪renderFieldWizard();
147  $fieldWizardHtml = $fieldWizardResult['html'];
148  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
149 
150  $mainFieldHtml = [];
151  $mainFieldHtml[] = '<div class="form-control-wrap" style="max-width: ' . $width . 'px">';
152  $mainFieldHtml[] = '<div class="form-wizards-wrap">';
153  $mainFieldHtml[] = '<div class="form-wizards-element">';
154  $mainFieldHtml[] = '<input type="email" ' . GeneralUtility::implodeAttributes($attributes, true) . ' />';
155  $mainFieldHtml[] = '<input type="hidden" name="' . $itemName . '" value="' . htmlspecialchars((string)$itemValue) . '" />';
156  $mainFieldHtml[] = '</div>';
157  if (!empty($fieldControlHtml)) {
158  $mainFieldHtml[] = '<div class="form-wizards-items-aside form-wizards-items-aside--field-control">';
159  $mainFieldHtml[] = '<div class="btn-group">';
160  $mainFieldHtml[] = $fieldControlHtml;
161  $mainFieldHtml[] = '</div>';
162  $mainFieldHtml[] = '</div>';
163  }
164  if (!empty($fieldWizardHtml)) {
165  $mainFieldHtml[] = '<div class="form-wizards-items-bottom">';
166  $mainFieldHtml[] = $fieldWizardHtml;
167  $mainFieldHtml[] = '</div>';
168  }
169  $mainFieldHtml[] = '</div>';
170  $mainFieldHtml[] = '</div>';
171  $mainFieldHtml = implode(LF, $mainFieldHtml);
172 
173  $nullControlNameEscaped = htmlspecialchars('control[active][' . $table . '][' . $this->data['databaseRow']['uid'] . '][' . $fieldName . ']');
174 
175  $fullElement = $mainFieldHtml;
176  if ($this->‪hasNullCheckboxButNoPlaceholder()) {
177  $checked = $itemValue !== null ? ' checked="checked"' : '';
178  $fullElement = [];
179  $fullElement[] = '<div class="t3-form-field-disable"></div>';
180  $fullElement[] = '<div class="form-check t3-form-field-eval-null-checkbox">';
181  $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="0" />';
182  $fullElement[] = '<input type="checkbox" class="form-check-input" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . ' />';
183  $fullElement[] = '<label class="form-check-label" for="' . $nullControlNameEscaped . '">';
184  $fullElement[] = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.nullCheckbox');
185  $fullElement[] = '</label>';
186  $fullElement[] = '</div>';
187  $fullElement[] = $mainFieldHtml;
188  $fullElement = implode(LF, $fullElement);
189  } elseif ($this->‪hasNullCheckboxWithPlaceholder()) {
190  $checked = $itemValue !== null ? ' checked="checked"' : '';
191  $placeholder = $shortenedPlaceholder = trim((string)($config['placeholder'] ?? ''));
192  if ($placeholder !== '') {
193  $shortenedPlaceholder = ‪GeneralUtility::fixed_lgd_cs($placeholder, 20);
194  if ($placeholder !== $shortenedPlaceholder) {
195  $overrideLabel = sprintf(
196  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'),
197  '<span title="' . htmlspecialchars($placeholder) . '">' . htmlspecialchars($shortenedPlaceholder) . '</span>'
198  );
199  } else {
200  $overrideLabel = sprintf(
201  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override'),
202  htmlspecialchars($placeholder)
203  );
204  }
205  } else {
206  $overrideLabel = $languageService->sL(
207  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.placeholder.override_not_available'
208  );
209  }
210  $fullElement = [];
211  $fullElement[] = '<div class="form-check t3js-form-field-eval-null-placeholder-checkbox">';
212  $fullElement[] = '<input type="hidden" name="' . $nullControlNameEscaped . '" value="0" />';
213  $fullElement[] = '<input type="checkbox" class="form-check-input" name="' . $nullControlNameEscaped . '" id="' . $nullControlNameEscaped . '" value="1"' . $checked . ' />';
214  $fullElement[] = '<label class="form-check-label" for="' . $nullControlNameEscaped . '">';
215  $fullElement[] = $overrideLabel;
216  $fullElement[] = '</label>';
217  $fullElement[] = '</div>';
218  $fullElement[] = '<div class="t3js-formengine-placeholder-placeholder">';
219  $fullElement[] = '<div class="form-control-wrap" style="max-width:' . $width . 'px">';
220  $fullElement[] = '<input type="text" class="form-control" disabled="disabled" value="' . htmlspecialchars($shortenedPlaceholder) . '" />';
221  $fullElement[] = '</div>';
222  $fullElement[] = '</div>';
223  $fullElement[] = '<div class="t3js-formengine-placeholder-formfield">';
224  $fullElement[] = $mainFieldHtml;
225  $fullElement[] = '</div>';
226  $fullElement = implode(LF, $fullElement);
227  }
228 
229  $resultArray['html'] = $renderedLabel . '
230  <div class="formengine-field-item t3js-formengine-field-item">
231  ' . $fieldInformationHtml . $fullElement . '
232  </div>';
233 
234  return $resultArray;
235  }
236 }
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixed_lgd_cs
‪static string fixed_lgd_cs(string $string, int $chars, string $appendString='...')
Definition: GeneralUtility.php:92
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\Element\EmailElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: EmailElement.php:33
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Backend\Form\Element\EmailElement\render
‪array render()
Definition: EmailElement.php:66
‪TYPO3\CMS\Backend\Form\Element\EmailElement
Definition: EmailElement.php:28
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldControl
‪array renderFieldControl()
Definition: AbstractFormElement.php:89
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪getLanguageService()
Definition: AbstractFormElement.php:456
‪TYPO3\CMS\Backend\Form\Element\EmailElement\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: EmailElement.php:43
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\formMaxWidth
‪int formMaxWidth($size=48)
Definition: AbstractFormElement.php:332
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:133
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderLabel
‪renderLabel(string $for)
Definition: AbstractFormElement.php:119
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldWizard
‪array renderFieldWizard()
Definition: AbstractFormElement.php:105
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\hasNullCheckboxWithPlaceholder
‪hasNullCheckboxWithPlaceholder()
Definition: AbstractFormElement.php:195
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:817
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\hasNullCheckboxButNoPlaceholder
‪hasNullCheckboxButNoPlaceholder()
Definition: AbstractFormElement.php:163
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77