1
|
|
|
<?php |
2
|
|
|
namespace DCNGmbH\MooxCore\Service; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the FluidTYPO3/FluidcontentCore project under GPLv2 or later. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use FluidTYPO3\Flux\Form; |
12
|
|
|
use FluidTYPO3\Flux\Service\FluxService; |
13
|
|
|
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility; |
14
|
|
|
use FluidTYPO3\Flux\Utility\MiscellaneousUtility; |
15
|
|
|
use FluidTYPO3\Flux\View\ViewContext; |
16
|
|
|
use FluidTYPO3\Flux\View\TemplatePaths; |
17
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ConfigurationService |
21
|
|
|
*/ |
22
|
|
|
class ConfigurationService extends FluxService implements SingletonInterface { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $variants = array(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $versions = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $defaults = array(); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function initializeObject() { |
43
|
|
|
$this->initializeDefaults(); |
44
|
|
|
$this->initializeVariants(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function initializeDefaults() { |
51
|
|
|
$typoScript = $this->getAllTypoScript(); |
52
|
|
|
$this->defaults = (array) $typoScript['plugin']['tx_mooxcore']['settings']['defaults']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function initializeVariants() { |
59
|
|
|
$variants = (array) $this->getAllRegisteredVariants(); |
60
|
|
|
foreach ($variants as $contentType => $registeredVariantExtensions) { |
61
|
|
|
if (TRUE === empty($registeredVariantExtensions)) { |
62
|
|
|
continue; |
63
|
|
|
} |
64
|
|
|
$this->variants[$contentType] = array(); |
65
|
|
|
foreach ($registeredVariantExtensions as $extensionKeyOrArray) { |
66
|
|
|
$icon = NULL; |
67
|
|
|
$versions = array(); |
68
|
|
|
if (TRUE === is_array($extensionKeyOrArray) && 3 === count($extensionKeyOrArray)) { |
69
|
|
|
list ($extensionKey, $labelReference, $icon) = $extensionKeyOrArray; |
70
|
|
|
} elseif (TRUE === is_array($extensionKeyOrArray) && 2 === count($extensionKeyOrArray)) { |
71
|
|
|
list ($extensionKey, $labelReference) = $extensionKeyOrArray; |
72
|
|
|
} else { |
73
|
|
|
$extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKeyOrArray); |
74
|
|
|
$labelReference = 'moox_core.variantLabel'; |
75
|
|
|
} |
76
|
|
|
$controllerName = 'CoreContent/' . ucfirst($contentType); |
77
|
|
|
$paths = $this->getViewConfigurationForExtensionName($extensionKey); |
78
|
|
|
$templatePaths = new TemplatePaths($paths); |
|
|
|
|
79
|
|
|
$files = $templatePaths->resolveAvailableTemplateFiles($controllerName); |
80
|
|
|
foreach ($files as $file) { |
81
|
|
|
$versions[] = basename($file, '.' . TemplatePaths::DEFAULT_FORMAT); |
82
|
|
|
} |
83
|
|
|
$versions = array_unique($versions); |
84
|
|
|
$this->versions[$contentType] = array($extensionKey => $versions); |
85
|
|
|
$this->variants[$contentType][] = array($extensionKey, $labelReference, $icon); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getDefaults() { |
94
|
|
|
return $this->defaults; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function getAllRegisteredVariants() { |
|
|
|
|
101
|
|
|
return (array) $GLOBALS['TYPO3_CONF_VARS']['DCNGmbH.MooxCore']['variants']; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $contentType |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getVariantExtensionKeysForContentType($contentType) { |
109
|
|
|
if (TRUE === isset($this->variants[$contentType])) { |
110
|
|
|
return $this->variants[$contentType]; |
111
|
|
|
} |
112
|
|
|
return array(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $contentType |
117
|
|
|
* @param string $variant |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
public function getVariantVersions($contentType, $variant) { |
121
|
|
|
if (TRUE === isset($this->versions[$contentType][$variant])) { |
122
|
|
|
return $this->versions[$contentType][$variant]; |
123
|
|
|
} |
124
|
|
|
return array(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $extensionKey |
129
|
|
|
* @param string $contentType |
130
|
|
|
* @param string $variant |
131
|
|
|
* @param string $version |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function resolveTemplateFileForVariant($extensionKey, $contentType, $variant = NULL, $version = NULL) { |
135
|
|
|
$paths = $this->getViewConfigurationForExtensionName(FALSE === empty($variant) ? $variant : $extensionKey); |
136
|
|
|
$templatePaths = new TemplatePaths($paths); |
|
|
|
|
137
|
|
|
$controllerName = 'CoreContent'; |
138
|
|
|
$controllerAction = FALSE === empty($version) ? $contentType . '/' . $version : $contentType; |
139
|
|
|
return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat($controllerName, $controllerAction); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string $extension |
144
|
|
|
* @param string $contentType |
145
|
|
|
* @param string $version |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getIconFromVersion($extension, $contentType, $version = NULL) { |
149
|
|
|
$extensionKey = ExtensionNamingUtility::getExtensionKey($extension); |
150
|
|
|
$templatePathAndFilename = $this->resolveTemplateFileForVariant($extensionKey, $contentType, $extension, $version); |
151
|
|
|
$paths = $this->getViewConfigurationForExtensionName($extensionKey); |
152
|
|
|
$templatePaths = new TemplatePaths($paths); |
|
|
|
|
153
|
|
|
$viewContext = new ViewContext($templatePathAndFilename, $extensionKey); |
154
|
|
|
$viewContext->setTemplatePaths($templatePaths); |
155
|
|
|
$viewContext->setSectionName('Configuration'); |
156
|
|
|
$form = FluxService::getFormFromTemplateFile($viewContext); |
157
|
|
|
if (FALSE === $form instanceof Form) { |
158
|
|
|
return ''; |
159
|
|
|
} else { |
160
|
|
|
return MiscellaneousUtility::getIconForTemplate($form); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: