263c33b40d935b1317bb129b48be83dff07c6c17
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldWizard / SelectIcons.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\Backend\Form\Utility\FormEngineUtility;
20
21 /**
22 * Render thumbnails of icons,
23 * typically used with type=group and internal_type=file and file_reference.
24 */
25 class SelectIcons extends AbstractNode
26 {
27 /**
28 * Render thumbnails of selected files
29 *
30 * @return array
31 */
32 public function render(): array
33 {
34 $result = $this->initializeResultArray();
35
36 $parameterArray = $this->data['parameterArray'];
37 $selectItems = $parameterArray['fieldConf']['config']['items'];
38
39 $selectItemCounter = 0;
40 foreach ($selectItems as $item) {
41 if ($item[1] === '--div--') {
42 continue;
43 } else {
44 $icon = !empty($item[2]) ? FormEngineUtility::getIconHtml($item[2], $item[0], $item[0]) : '';
45 if ($icon) {
46 $selectIcons[] = [
47 'title' => $item[0],
48 'icon' => $icon,
49 'index' => $selectItemCounter,
50 ];
51 }
52 $selectItemCounter++;
53 }
54 }
55
56 $html = [];
57 if (!empty($selectIcons)) {
58 $html[] = '<div class="t3js-forms-select-single-icons icon-list">';
59 $html[] = '<div class="row">';
60 foreach ($selectIcons as $i => $selectIcon) {
61 $html[] = '<div class="item">';
62 if (is_array($selectIcon)) {
63 $html[] = '<a href="#" title="' . htmlspecialchars($selectIcon['title'], ENT_COMPAT, 'UTF-8', false) . '" data-select-index="' . htmlspecialchars((string)$selectIcon['index']) . '">';
64 $html[] = $selectIcon['icon'];
65 $html[] = '</a>';
66 }
67 $html[] = '</div>';
68 }
69 $html[] = '</div>';
70 $html[] = '</div>';
71 }
72
73 $result['html'] = implode(LF, $html);
74 return $result;
75 }
76 }