1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Icon loader. |
5
|
|
|
*/ |
6
|
|
|
declare(strict_types = 1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Autoloader\Loader; |
9
|
|
|
|
10
|
|
|
use HDNET\Autoloader\Loader; |
11
|
|
|
use HDNET\Autoloader\LoaderInterface; |
12
|
|
|
use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider; |
13
|
|
|
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider; |
14
|
|
|
use TYPO3\CMS\Core\Imaging\IconRegistry; |
15
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
17
|
|
|
use TYPO3\CMS\Core\Utility\PathUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Icon loader. |
21
|
|
|
*/ |
22
|
|
|
class Icon implements LoaderInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Get all the complex data for the loader. |
26
|
|
|
* This return value will be cached and stored in the database |
27
|
|
|
* There is no file monitoring for this cache. |
28
|
|
|
*/ |
29
|
|
|
public function prepareLoader(Loader $loader, int $type): array |
30
|
|
|
{ |
31
|
|
|
$icons = []; |
32
|
|
|
if (!class_exists(IconRegistry::class)) { |
33
|
|
|
return $icons; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return array_merge($this->getIconsByPath($loader, 'Resources/Public/Icon/'), $this->getIconsByPath($loader, 'Resources/Public/Icons/')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Run the loading process for the ext_tables.php file. |
41
|
|
|
*/ |
42
|
|
|
public function loadExtensionTables(Loader $loader, array $loaderInformation): void |
43
|
|
|
{ |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Run the loading process for the ext_localconf.php file. |
48
|
|
|
* |
49
|
|
|
* @internal param \HDNET\Autoloader\Loader $autoLoader |
50
|
|
|
*/ |
51
|
|
|
public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void |
52
|
|
|
{ |
53
|
|
|
if (empty($loaderInformation)) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @var IconRegistry $iconRegistry */ |
58
|
|
|
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class); |
59
|
|
|
|
60
|
|
|
foreach ($loaderInformation as $config) { |
61
|
|
|
$iconRegistry->registerIcon($config['identifier'], $config['provider'], ['source' => $config['path']]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the icons. |
67
|
|
|
* |
68
|
|
|
* @param string $relPath |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getIconsByPath(Loader $loader, $relPath) |
73
|
|
|
{ |
74
|
|
|
$icons = []; |
75
|
|
|
$folder = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . $relPath; |
76
|
|
|
$extensionPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()); |
77
|
|
|
$files = GeneralUtility::getAllFilesAndFoldersInPath([], $folder, '', false, 99); |
78
|
|
|
if (!\count($files)) { |
79
|
|
|
return $icons; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
foreach ($files as $path) { |
83
|
|
|
$provider = BitmapIconProvider::class; |
84
|
|
|
if ('svg' === mb_substr(mb_strtolower($path), -3)) { |
85
|
|
|
$provider = SvgIconProvider::class; |
86
|
|
|
} |
87
|
|
|
$relativePath = str_replace($extensionPath, '', $path); |
88
|
|
|
$iconPath = str_replace($relPath, '', $relativePath); |
89
|
|
|
|
90
|
|
|
$pathElements = PathUtility::pathinfo(mb_strtolower(str_replace(['/', '_'], '-', GeneralUtility::camelCaseToLowerCaseUnderscored($iconPath)))); |
91
|
|
|
$icons[] = [ |
92
|
|
|
'provider' => $provider, |
93
|
|
|
'path' => 'EXT:' . $loader->getExtensionKey() . '/' . $relativePath, |
94
|
|
|
'identifier' => str_replace('_', '-', $loader->getExtensionKey()) . '-' . $pathElements['filename'], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $icons; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|