Skip to content

Commit 6bb1e37

Browse files
authored
Merge pull request #17 from punktDe/FixUndefinedArrayKeyWarning
[FIX] Check if array keys exist before accessing
2 parents 18060c4 + 6a4ef30 commit 6bb1e37

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

Classes/Backend/PageLayoutHeader.php

+38-7
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,18 @@ protected function toolbarIsEnabledForUser(): bool
120120
$isEnabled = false;
121121
}
122122

123-
if ($this->backendUser->user['quickedit_disableToolbar']) {
123+
if (
124+
array_key_exists('quickedit_disableToolbar', $this->backendUser->user) &&
125+
$this->backendUser->user['quickedit_disableToolbar']
126+
) {
124127
$isEnabled = false;
125128
}
126129

127130
foreach ($this->backendUser->userGroups as $group) {
128-
if ($group['quickedit_disableToolbar']) {
131+
if (
132+
array_key_exists('quickedit_disableToolbar', $group) &&
133+
$group['quickedit_disableToolbar']
134+
) {
129135
$isEnabled = false;
130136
}
131137
}
@@ -168,7 +174,7 @@ protected function getFieldConfigForPage(): array
168174
{
169175
$configForPageType = $this->getConfigForCurrentPage();
170176

171-
if (is_array($configForPageType) && count($configForPageType) > 0) {
177+
if (count($configForPageType) > 0) {
172178
foreach ($configForPageType as $key => &$singleConfig) {
173179
$singleConfig['fields'] = $this->prepareFieldsList($singleConfig['fields']);
174180

@@ -200,12 +206,21 @@ protected function getFieldConfigForPage(): array
200206
protected function getConfigForCurrentPage(): array
201207
{
202208
$pageTsConfig = BackendUtility::getPagesTSconfig($this->pageUid);
203-
$quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.'];
204209
$configForPageType = [];
205210

206-
if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) {
207-
$configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.'];
208-
ksort($configForPageType);
211+
if (
212+
array_key_exists('mod.', $pageTsConfig) &&
213+
is_array($pageTsConfig['mod.']) &&
214+
array_key_exists('web_layout.', $pageTsConfig['mod.']) &&
215+
is_array($pageTsConfig['mod.']['web_layout.']) &&
216+
array_key_exists('PageTypes.', $pageTsConfig['mod.']['web_layout.'])
217+
) {
218+
$quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.'];
219+
220+
if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) {
221+
$configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.'];
222+
ksort($configForPageType);
223+
}
209224
}
210225

211226
return $configForPageType;
@@ -229,6 +244,11 @@ protected function prepareFieldsList(string $fields): string
229244
$fieldsArray = array_map('trim', $fieldsArray);
230245

231246
foreach ($fieldsArray as $index => $field) {
247+
if ($this->isFieldDefined($field) === false) {
248+
unset($fieldsArray[$index]);
249+
continue;
250+
}
251+
232252
if ($this->userHasAccessToField($field) === false
233253
|| $this->fieldIsAvailableForLanguage($field) === false) {
234254
unset($fieldsArray[$index]);
@@ -340,4 +360,15 @@ protected function isVisible(): bool
340360

341361
return $isVisible;
342362
}
363+
364+
365+
366+
/**
367+
* @param string $field
368+
* @return bool
369+
*/
370+
protected function isFieldDefined(string $field): bool
371+
{
372+
return array_key_exists($field, $GLOBALS['TCA']['pages']['columns']);
373+
}
343374
}

Documentation/Changelog/Index.rst

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
Change log
77
==========
88

9+
Version 1.0.1
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 1.0.0
1017
-------------
1118

12-
- Update extension for TYPO3 11 LTS support
19+
- Update extension for TYPO3 11 LTS support (https://github.com/punktDe/quickedit/issues/6)
20+
21+
Version 0.2.2
22+
-------------
23+
24+
- Fix php warning by accessing non existing array keys (https://github.com/punktDe/quickedit/issues/15)
25+
- Further code improvements
1326

1427
Version 0.2.1
1528
-------------

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 = 1.0.0
28+
release = 1.0.1
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' => '1.0.0',
5+
'version' => '1.0.1',
66
'category' => 'be',
77
'constraints' => [
88
'depends' => [

0 commit comments

Comments
 (0)