Gridelement   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 7
dl 0
loc 100
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B prepareLoader() 0 37 6
A loadExtensionTables() 0 3 1
A loadExtensionConfiguration() 0 8 2
A getPageTsConfig() 0 23 3
1
<?php
2
3
/**
4
 * Loading Gridelements.
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 HDNET\Autoloader\Utility\FileUtility;
13
use HDNET\Autoloader\Utility\IconUtility;
14
use HDNET\Autoloader\Utility\TranslateUtility;
15
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Core\Utility\PathUtility;
18
19
/**
20
 * Loading Gridelements.
21
 */
22
class Gridelement 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
        $grids = [];
32
        if (!ExtensionManagementUtility::isLoaded('gridelements')) {
33
            return $grids;
34
        }
35
36
        $commandPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Resources/Private/Grids/';
37
        $files = FileUtility::getBaseFilesWithExtensionInDir($commandPath, 'ts,txt,typoscript');
38
39
        foreach ($files as $file) {
40
            $pathInfo = PathUtility::pathinfo($file);
41
            $iconPath = 'EXT:' . $loader->getExtensionKey() . '/Resources/Public/Icons/Grids/' . $pathInfo['filename'] . '.';
42
            $extension = IconUtility::getIconFileExtension(GeneralUtility::getFileAbsFileName($iconPath));
43
44
            $translationKey = 'grid.' . $pathInfo['filename'];
45
            $translationKeyDescription = $translationKey . '.description';
46
            if (LoaderInterface::EXT_TABLES === $type) {
47
                TranslateUtility::assureLabel($translationKey, $loader->getExtensionKey(), $pathInfo['filename']);
48
                TranslateUtility::assureLabel($translationKeyDescription, $loader->getExtensionKey(), $pathInfo['filename'] . ' description ');
49
            }
50
51
            $path = 'EXT:' . $loader->getExtensionKey() . '/Resources/Private/Grids/' . $file;
52
            $icon = $extension ? $iconPath . $extension : false;
53
            $label = TranslateUtility::getLllString($translationKey, $loader->getExtensionKey());
54
            $description = TranslateUtility::getLllString($translationKeyDescription, $loader->getExtensionKey());
55
            $content = GeneralUtility::getUrl(GeneralUtility::getFileAbsFileName($path));
56
57
            $flexForm = 'EXT:' . $loader->getExtensionKey() . '/Configuration/FlexForms/Grids/' . $pathInfo['filename'] . '.xml';
58
            $flexFormFile = GeneralUtility::getFileAbsFileName($flexForm);
59
            $flexFormContent = is_file($flexFormFile) ? GeneralUtility::getUrl($flexFormFile) : false;
60
61
            $grids[] = $this->getPageTsConfig($pathInfo['filename'], $label, $content, $icon, $flexFormContent, $description);
62
        }
63
64
        return $grids;
65
    }
66
67
    /**
68
     * Run the loading process for the ext_tables.php file.
69
     */
70
    public function loadExtensionTables(Loader $loader, array $loaderInformation): void
71
    {
72
    }
73
74
    /**
75
     * Run the loading process for the ext_localconf.php file.
76
     */
77
    public function loadExtensionConfiguration(Loader $loader, array $loaderInformation): void
78
    {
79
        if (empty($loaderInformation)) {
80
            return;
81
        }
82
83
        ExtensionManagementUtility::addPageTSConfig(implode("\n", $loaderInformation));
84
    }
85
86
    /**
87
     * Get the Page TS config for the grid.
88
     *
89
     * @param $id
90
     * @param $label
91
     * @param $config
92
     * @param $icon
93
     * @param $flexForm
94
     * @param $description
95
     *
96
     * @return string
97
     */
98
    protected function getPageTsConfig($id, $label, $config, $icon, $flexForm, $description)
99
    {
100
        $lines = [];
101
        $lines[] = 'tx_gridelements.setup {';
102
        $lines[] = $id . ' {';
103
104
        $lines[] = 'title = ' . $label;
105
        $lines[] = 'description = ' . $description;
106
        if ($icon) {
107
            $lines[] = 'icon = ' . $icon;
108
        }
109
        $lines[] = $config;
110
        if ($flexForm) {
111
            $lines[] = 'flexformDS (';
112
            $lines[] = $flexForm;
113
            $lines[] = ')';
114
        }
115
116
        $lines[] = '}';
117
        $lines[] = '}';
118
119
        return implode("\n", $lines);
120
    }
121
}
122