‪TYPO3CMS  ‪main
FieldMapElement.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 
21 
30 {
36  protected ‪$defaultFieldInformation = [
37  'tcaDescription' => [
38  'renderType' => 'tcaDescription',
39  ],
40  ];
41 
42  protected array ‪$supportedFieldTypes = ['input', 'textarea', 'text', 'email', 'number', 'datetime', 'color'];
43 
44  public function ‪render(): array
45  {
46  $languageService = $this->‪getLanguageService();
47  $resultArray = $this->‪initializeResultArray();
48  $parameterArray = $this->data['parameterArray'];
49  $itemValue = $parameterArray['itemFormElValue'];
50  $itemName = $parameterArray['itemFormElName'];
51 
52  $tableName = (string)($this->data['databaseRow']['table_name'][0] ?? '');
53  $columns = ‪$GLOBALS['TCA'][$tableName]['columns'] ?? [];
54 
55  $fieldsHtml = '';
56  if (is_array($columns) && $columns !== []) {
57  foreach ($columns as $fieldName => $fieldConfig) {
58  if (!in_array($fieldConfig['config']['type'], $this->supportedFieldTypes, true)) {
59  continue;
60  }
61  $fieldName = htmlspecialchars($fieldName);
62  $fieldValue = is_array($itemValue) && isset($itemValue[$fieldName]) ? htmlspecialchars((string)$itemValue[$fieldName]) : '';
63  $fieldsHtml .= '
64  <div class="form-group">
65  <label class="form-label" for="' . $fieldName . '">
66  ' . $languageService->sL($fieldConfig['label']) . '
67  </label>
68  <input type="text" class="form-control" id="' . $fieldName . '" name="' . htmlspecialchars($itemName) . '[' . $fieldName . ']" value="' . $fieldValue . '">
69  </div>';
70  }
71  }
72 
73  if ($fieldsHtml !== '') {
74  $fieldsHtml = '<div class="row">' . $fieldsHtml . '</div>';
75  } else {
76  $fieldsHtml = '
77  <div class="alert alert-warning">
78  ' . htmlspecialchars(sprintf($languageService->sL('LLL:EXT:reactions/Resources/Private/Language/locallang_db.xlf:fieldMapElement.noFields'), $tableName)) . '
79  </div>';
80  }
81 
82  $fieldInformationResult = $this->‪renderFieldInformation();
83  $fieldInformationHtml = $fieldInformationResult['html'];
84  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
85 
86  $html = [];
87  $html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
88  $html[] = $fieldInformationHtml;
89  $html[] = '<div class="form-control-wrap" style="max-width: ' . $this->‪formMaxWidth($this->defaultInputWidth) . 'px">';
90  $html[] = '<div class="form-wizards-wrap">';
91  $html[] = '<div class="form-wizards-element">';
92  $html[] = $fieldsHtml;
93  $html[] = '</div>';
94  $html[] = '</div>';
95  $html[] = '</div>';
96  $html[] = '</div>';
97  $resultArray['html'] = $this->‪wrapWithFieldsetAndLegend(implode(LF, $html));
98  return $resultArray;
99  }
100 }
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\renderFieldInformation
‪array renderFieldInformation()
Definition: AbstractFormElement.php:73
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Reactions\Form\Element\FieldMapElement\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: FieldMapElement.php:35
‪TYPO3\CMS\Reactions\Form\Element\FieldMapElement\render
‪render()
Definition: FieldMapElement.php:43
‪TYPO3\CMS\Reactions\Form\Element\FieldMapElement\$supportedFieldTypes
‪array $supportedFieldTypes
Definition: FieldMapElement.php:41
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\wrapWithFieldsetAndLegend
‪wrapWithFieldsetAndLegend(string $innerHTML)
Definition: AbstractFormElement.php:133
‪TYPO3\CMS\Reactions\Form\Element
Definition: FieldMapElement.php:18
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪getLanguageService()
Definition: AbstractFormElement.php:456
‪TYPO3\CMS\Reactions\Form\Element\FieldMapElement
Definition: FieldMapElement.php:30
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\formMaxWidth
‪int formMaxWidth($size=48)
Definition: AbstractFormElement.php:332
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77