TYPO3 CMS  TYPO3_8-7
SelectIcons.php
Go to the documentation of this file.
1 <?php
2 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 
20 
26 {
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  }
44  $icon = !empty($item[2]) ? FormEngineUtility::getIconHtml($item[2], $item[0], $item[0]) : '';
45  if ($icon) {
46  $fieldValue = $this->data['databaseRow'][$this->data['fieldName']];
47  $selectIcons[] = [
48  'title' => $item[0],
49  'active' => ($fieldValue[0] === (string)$item[1]) ? true : false,
50  'icon' => $icon,
51  'index' => $selectItemCounter,
52  ];
53  }
54  $selectItemCounter++;
55  }
56 
57  $html = [];
58  if (!empty($selectIcons)) {
59  $html[] = '<div class="t3js-forms-select-single-icons icon-list">';
60  $html[] = '<div class="row">';
61  foreach ($selectIcons as $i => $selectIcon) {
62  $active = ($selectIcon['active']) ? ' active' : '';
63  $html[] = '<div class="item' . $active . '">';
64  if (is_array($selectIcon)) {
65  $html[] = '<a href="#" title="' . htmlspecialchars($selectIcon['title'], ENT_COMPAT, 'UTF-8', false) . '" data-select-index="' . htmlspecialchars((string)$selectIcon['index']) . '">';
66  $html[] = $selectIcon['icon'];
67  $html[] = '</a>';
68  }
69  $html[] = '</div>';
70  }
71  $html[] = '</div>';
72  $html[] = '</div>';
73  }
74 
75  $result['html'] = implode(LF, $html);
76  return $result;
77  }
78 }
static getIconHtml($icon, $alt='', $title='')