[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldWizard / FileTypeList.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Backend\Form\FieldWizard;
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
18 use TYPO3\CMS\Backend\Form\AbstractNode;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Render list of allowed / disalowwed file types,
23 * typically used with type=group and internal_type=file.
24 */
25 class FileTypeList extends AbstractNode
26 {
27 /**
28 * Render list of allowed and disallowed file types
29 *
30 * @return array
31 */
32 public function render(): array
33 {
34 $result = $this->initializeResultArray();
35
36 $parameterArray = $this->data['parameterArray'];
37 $config = $parameterArray['fieldConf']['config'];
38
39 if (!isset($config['allowed']) || !is_string($config['allowed']) || empty($config['allowed'])
40 || !isset($config['internal_type']) || $config['internal_type'] !== 'file'
41 ) {
42 // No handling if the field has no, or funny "allowed" setting, and if internal_type is not "file"
43 return $result;
44 }
45
46 $allowed = GeneralUtility::trimExplode(',', $config['allowed'], true);
47 $disallowed = isset($config['disallowed']) ? GeneralUtility::trimExplode(',', $config['disallowed'], true) : [];
48
49 $allowedHtml = [];
50 foreach ($allowed as $item) {
51 $allowedHtml[] = '<span class="label label-success">' . htmlspecialchars(strtoupper($item)) . '</span> ';
52 }
53 $disallowedHtml = [];
54 foreach ($disallowed as $item) {
55 $disallowedHtml[] = '<span class="label label-danger">' . htmlspecialchars(strtoupper($item)) . '</span> ';
56 }
57 $html = [];
58 if (!empty($allowedHtml) || !empty($disallowedHtml)) {
59 $html[] = '<div class="help-block">';
60 $html[] = implode(LF, $allowedHtml);
61 $html[] = implode(LF, $disallowedHtml);
62 $html[] = '</div>';
63 }
64
65 $result['html'] = implode(LF, $html);
66 return $result;
67 }
68 }