Skip to content

Commit 4c278ee

Browse files
authored
Merge pull request #18 from punktDe/BackportFixUndefinedArrayKeyWarning
Backport fix undefined array key warning
2 parents 0421e22 + 81692b5 commit 4c278ee

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

Classes/Backend/PageLayoutHeader.php

+38-7
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ protected function toolbarIsEnabledForUser(): bool
117117
$isEnabled = false;
118118
}
119119

120-
if ($this->backendUser->user['quickedit_disableToolbar']) {
120+
if (
121+
array_key_exists('quickedit_disableToolbar', $this->backendUser->user) &&
122+
$this->backendUser->user['quickedit_disableToolbar']
123+
) {
121124
$isEnabled = false;
122125
}
123126

124127
foreach ($this->backendUser->userGroups as $group) {
125-
if ($group['quickedit_disableToolbar']) {
128+
if (
129+
array_key_exists('quickedit_disableToolbar', $group) &&
130+
$group['quickedit_disableToolbar']
131+
) {
126132
$isEnabled = false;
127133
}
128134
}
@@ -165,7 +171,7 @@ protected function getFieldConfigForPage(): array
165171
{
166172
$configForPageType = $this->getConfigForCurrentPage();
167173

168-
if (is_array($configForPageType) && count($configForPageType) > 0) {
174+
if (count($configForPageType) > 0) {
169175
foreach ($configForPageType as $key => &$singleConfig) {
170176
$singleConfig['fields'] = $this->prepareFieldsList($singleConfig['fields']);
171177

@@ -197,12 +203,21 @@ protected function getFieldConfigForPage(): array
197203
protected function getConfigForCurrentPage(): array
198204
{
199205
$pageTsConfig = BackendUtility::getPagesTSconfig($this->pageUid);
200-
$quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.'];
201206
$configForPageType = [];
202207

203-
if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) {
204-
$configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.'];
205-
ksort($configForPageType);
208+
if (
209+
array_key_exists('mod.', $pageTsConfig) &&
210+
is_array($pageTsConfig['mod.']) &&
211+
array_key_exists('web_layout.', $pageTsConfig['mod.']) &&
212+
is_array($pageTsConfig['mod.']['web_layout.']) &&
213+
array_key_exists('PageTypes.', $pageTsConfig['mod.']['web_layout.'])
214+
) {
215+
$quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.'];
216+
217+
if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) {
218+
$configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.'];
219+
ksort($configForPageType);
220+
}
206221
}
207222

208223
return $configForPageType;
@@ -226,6 +241,11 @@ protected function prepareFieldsList(string $fields): string
226241
$fieldsArray = array_map('trim', $fieldsArray);
227242

228243
foreach ($fieldsArray as $index => $field) {
244+
if ($this->isFieldDefined($field) === false) {
245+
unset($fieldsArray[$index]);
246+
continue;
247+
}
248+
229249
if ($this->userHasAccessToField($field) === false
230250
|| $this->fieldIsAvailableForLanguage($field) === false) {
231251
unset($fieldsArray[$index]);
@@ -337,4 +357,15 @@ protected function isVisible(): bool
337357

338358
return $isVisible;
339359
}
360+
361+
362+
363+
/**
364+
* @param string $field
365+
* @return bool
366+
*/
367+
protected function isFieldDefined(string $field): bool
368+
{
369+
return array_key_exists($field, $GLOBALS['TCA']['pages']['columns']);
370+
}
340371
}

Documentation/Changelog/Index.rst

+8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
Change log
77
==========
88

9+
Version 0.2.2
10+
-------------
11+
12+
- Fix php warning by accessing non existing array keys (https://github.com/punktDe/quickedit/issues/15)
13+
- Further code improvements
14+
- Update README.md example code (https://github.com/punktDe/quickedit/issues/19)
15+
916
Version 0.2.1
1017
-------------
18+
1119
- Fix missing extension icon issue (https://github.com/punktDe/quickedit/issues/7)
1220
- Fix missing collapse/hide icons in TYPO3 10 (https://github.com/punktDe/quickedit/issues/8)
1321

Documentation/Settings.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ project = Quickedit
2525
# ... (recommended) version, displayed next to title (desktop) and in <meta name="book-version"
2626
# .................................................................................
2727

28-
release = 0.2.1
28+
release = 0.2.2
2929

3030
# .................................................................................
3131
# ... (recommended) displayed in footer

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod {
4545
}
4646
2 {
4747
label = Special
48-
fields = slug, suergroup, hidden
48+
fields = slug, hidden, fe_group
4949
previewFields = *
5050
}
5151
}

ext_emconf.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$EM_CONF[$_EXTKEY] = [
33
'title' => 'Toolbar for editing page properties',
44
'description' => 'This extension provides a configurable toolbar for editing page properties.',
5-
'version' => '0.2.1',
5+
'version' => '0.2.2',
66
'category' => 'be',
77
'constraints' => [
88
'depends' => [

0 commit comments

Comments
 (0)