forked from Digi92/dw_content_elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext_tables.php
More file actions
executable file
·232 lines (201 loc) · 10.5 KB
/
ext_tables.php
File metadata and controls
executable file
·232 lines (201 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
$_EXTKEY,
'Configuration/TypoScript',
'Content element configuration'
);
// Extension manager configuration: used as default configuration
$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dw_content_elements']);
// get configurations from localconf
$configurations = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dw_content_elements'];
// initialize provieders array
$providers = array();
if (isset($configurations['provider']) && count($configurations['provider'])) {
foreach ($configurations['provider'] as $extKey => $config) {
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey) && is_array($config)) {
$providers[$extKey] = $config;
}
}
} elseif (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dw_content_elements_source')) {
$providers['dw_content_elements_source'] = array(
'pluginName' => 'ContentRenderer',
'controllerActions' => array('Elements' => 'render')
);
}
//Source Extension Installiert
if (count($providers) > 0) {
$typoScript = '[GLOBAL] ';
foreach ($providers as $provider => $providerConfig) {
// Set default values for provider configuration
if (!isset($providerConfig['addElementsToWizard'])) {
$providerConfig['addElementsToWizard'] = $configuration['addElementsToWizard'];
}
if (!isset($providerConfig['elementWizardTabTitle']) || empty($providerConfig['elementWizardTabTitle'])) {
$providerConfig['elementWizardTabTitle'] = $configuration['elementWizardTabTitle'];
}
if (!isset($providerConfig['pluginCategory']) || empty($providerConfig['pluginCategory'])) {
$providerConfig['pluginCategory'] =
'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xlf:mlang_tabs_tab';
}
// generate camelcase version of the provider
$providerNameCamelCase = preg_replace_callback('/_([a-z])/', function ($c) {
return strtoupper($c[1]);
}, $provider);
//Add content element wizard tab
if ((bool)$providerConfig['addElementsToWizard'] === true &&
(bool)$configuration['addElementsToWizard'] === true
) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'mod.wizards.newContentElement.wizardItems.' . $providerNameCamelCase . ' {
header = ' . $providerConfig['elementWizardTabTitle'] . '
show = *
}'
);
}
//Set own optgroup on the ctype select
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'][] = array(
0 => $providerConfig['pluginCategory'],
1 => '--div--'
);
// build elements path
$elementsPath = (isset($providerConfig['elementsPath']) && !empty($providerConfig['elementsPath'])) ?
$providerConfig['elementsPath'] :
'/Configuration/Elements';
//Get all config files
$path = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Denkwerk\DwContentElements\Utility\Pathes');
$contentElements = $path->getAllDirFiles(
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($provider) . $elementsPath
);
//Add new content elements
if (is_array($contentElements) && empty($contentElements) === false) {
foreach ($contentElements as $key => $element) {
//Load element config
$elementConfig = \Denkwerk\DwContentElements\Service\Ini::getInstance()
->setConfigFile($element)
->loadConfig();
if (isset($elementConfig['title'])) {
//Add element plugin
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
array(
$elementConfig['title'],
lcfirst($key)
),
'CType',
$provider
);
//Set element showitem
if ((bool)$elementConfig['overWriteShowitem'] === true) {
$showItem = trim((string)$elementConfig['fields'], ',');
} else {
$showItem = 'CType;;4;button;1-1-1, --palette--;Headline,'
. trim((string)$elementConfig['fields'], ',') . ',
--div--;LLL:EXT:cms/locallang_tca.xlf:pages.tabs.access,
--palette--;LLL:EXT:cms/locallang_tca.xlf:pages.palettes.visibility;hiddenonly,
--palette--;LLL:EXT:cms/locallang_tca.xlf:pages.palettes.access;access';
}
$TCA['tt_content']['types'][lcfirst($key)]['showitem'] = $showItem;
$TCA['tt_content']['types'][lcfirst($key)]['tx_dw_content_elements_title'] =
(string)$elementConfig['title'];
//Add tab extends and if the palette "dwcAdditionalFields" exists add the fields of it
$TCA['tt_content']['types'][lcfirst($key)]['showitem'] .= ',
--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xml:pages.tabs.extended,
--palette--;LLL:EXT:' . $_EXTKEY .
'/Resources/Private/Language/locallang_db.xlf:palettes.dwcAdditionalFields;dwcAdditionalFields';
// Fix for the extension GridElements. GridElements needs in all elements the
// fields "tx_gridelements_container,tx_gridelements_columns"
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('gridelements')) {
$TCA['tt_content']['types'][lcfirst($key)]['showitem'] .=
',tx_gridelements_container,tx_gridelements_columns';
}
$TCA['tt_content']['types'][lcfirst($key)]['showitem'] .=
',colPos';
//Set rendering typoScript
$typoScript .= "\n
tt_content." . lcfirst($key) .
" < tt_content.list.20." .
strtolower($providerNameCamelCase) . "_" . strtolower($providerConfig['pluginName']) . " \n";
foreach ($providerConfig['controllerActions'] as $controller => $actions) {
$actionArray = explode(',', $actions);
foreach ($actionArray as $index => $action) {
$typoScript .= "tt_content." .
lcfirst($key) . ".switchableControllerActions." .
$controller . "." . ($index + 1) . " = " .
$action . " \n";
}
}
//Add content elements to the content elements wizard
if ((bool)$providerConfig['addElementsToWizard'] === true &&
(bool)$configuration['addElementsToWizard'] === true
) {
if (version_compare(TYPO3_branch, '7.6', '<')) {
// Fallback for TYPO3 6.2
// Fallback icon
$iconPath = '../../typo3conf/ext/' . $_EXTKEY . '/ext_icon.png';
// Set custom icon
if ($elementConfig['icon']) {
$iconPath = (string)$elementConfig['icon'];
}
// Add the icon to the content element config
$icon = 'icon = ' . $iconPath;
} else {
// Fallback icon
$iconIdentifier = 'content-textpic';
// Registration the content element icon, if set
if ($elementConfig['icon']) {
/** @var \TYPO3\CMS\Core\Imaging\IconRegistry $iconRegistry */
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Imaging\\IconRegistry'
);
$iconIdentifier = 'dwc-' . lcfirst($key);
$iconRegistry->registerIcon(
$iconIdentifier,
\TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
array(
'source' => (string)$elementConfig['icon']
)
);
}
// Add the icon to the content element config
$icon = 'iconIdentifier = ' . $iconIdentifier;
}
// Set conten element wizardItems
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
mod.wizards.newContentElement.wizardItems.' .
$providerNameCamelCase . '.elements.' . lcfirst($key) . ' {
' . $icon . '
title = ' . (string)$elementConfig['title'] . '
description = ' . (string)$elementConfig['description'] . '
tt_content_defValues.CType = ' . lcfirst($key) . '
}
');
}
}
}
}
}
//Add rendering typoScript
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript(
$_EXTKEY,
'setup',
$typoScript,
true
);
}
//Add backend module
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'Denkwerk.' . $_EXTKEY, // vendor + extkey, seperated by a dot
'tools', // Backend Module group to place the module in
'DW Content Elements', // module name
'', // position in the group
array( // Allowed controller -> action combinations
'Backend' => 'index, createSourceExt, loadSourceExt',
),
array( // Additional configuration
'access' => 'user,group',
'icon' => 'EXT:' . $_EXTKEY . '/ext_icon.png',
'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xlf',
)
);