TYPO3 CMS  TYPO3_8-7
FileTypeList.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  $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 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)