From 0b896c06d6ca95a8b1920da251f031113c5f4628 Mon Sep 17 00:00:00 2001 From: Alexander Boehm Date: Fri, 14 Oct 2022 06:58:05 +0200 Subject: [PATCH 1/4] [FIX] Check if array keys exist before accessing --- Classes/Backend/PageLayoutHeader.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Classes/Backend/PageLayoutHeader.php b/Classes/Backend/PageLayoutHeader.php index bcbd764..f5a242d 100644 --- a/Classes/Backend/PageLayoutHeader.php +++ b/Classes/Backend/PageLayoutHeader.php @@ -165,7 +165,7 @@ protected function getFieldConfigForPage(): array { $configForPageType = $this->getConfigForCurrentPage(); - if (is_array($configForPageType) && count($configForPageType) > 0) { + if (count($configForPageType) > 0) { foreach ($configForPageType as $key => &$singleConfig) { $singleConfig['fields'] = $this->prepareFieldsList($singleConfig['fields']); @@ -197,12 +197,21 @@ protected function getFieldConfigForPage(): array protected function getConfigForCurrentPage(): array { $pageTsConfig = BackendUtility::getPagesTSconfig($this->pageUid); - $quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.']; $configForPageType = []; - if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) { - $configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.']; - ksort($configForPageType); + if ( + array_key_exists('mod.', $pageTsConfig) && + is_array($pageTsConfig['mod.']) && + array_key_exists('web_layout.', $pageTsConfig['mod.']) && + is_array($pageTsConfig['mod.']['web_layout.']) && + array_key_exists('PageTypes.', $pageTsConfig['mod.']['web_layout.']) + ) { + $quickeditConfig = $pageTsConfig['mod.']['web_layout.']['PageTypes.']; + + if (is_array($quickeditConfig) && array_key_exists($this->pageRecord['doktype'] . '.', $quickeditConfig)) { + $configForPageType = $quickeditConfig[$this->pageRecord['doktype'] . '.']['config.']; + ksort($configForPageType); + } } return $configForPageType; From 2582603a2ecfa4be5b2a66cd728af83747ed419d Mon Sep 17 00:00:00 2001 From: Alexander Boehm Date: Fri, 14 Oct 2022 07:15:21 +0200 Subject: [PATCH 2/4] [TASK] Update extension version and changelog --- Documentation/Changelog/Index.rst | 6 ++++++ Documentation/Settings.cfg | 2 +- ext_emconf.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 0377700..95fdcea 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -6,8 +6,14 @@ Change log ========== +Version 0.2.2 +------------- + +- Fix php warning by accessing non existing array keys (https://github.com/punktDe/quickedit/issues/15) + Version 0.2.1 ------------- + - Fix missing extension icon issue (https://github.com/punktDe/quickedit/issues/7) - Fix missing collapse/hide icons in TYPO3 10 (https://github.com/punktDe/quickedit/issues/8) diff --git a/Documentation/Settings.cfg b/Documentation/Settings.cfg index 9346548..219ba7d 100644 --- a/Documentation/Settings.cfg +++ b/Documentation/Settings.cfg @@ -25,7 +25,7 @@ project = Quickedit # ... (recommended) version, displayed next to title (desktop) and in 'Toolbar for editing page properties', 'description' => 'This extension provides a configurable toolbar for editing page properties.', - 'version' => '0.2.1', + 'version' => '0.2.2', 'category' => 'be', 'constraints' => [ 'depends' => [ From 44fa1a0dc9e9a6dccb9a189ce1f60961674e0984 Mon Sep 17 00:00:00 2001 From: Alexander Boehm Date: Wed, 26 Oct 2022 08:02:52 +0200 Subject: [PATCH 3/4] [TASK] Further array checks --- Classes/Backend/PageLayoutHeader.php | 26 ++++++++++++++++++++++++-- Documentation/Changelog/Index.rst | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Classes/Backend/PageLayoutHeader.php b/Classes/Backend/PageLayoutHeader.php index f5a242d..517498e 100644 --- a/Classes/Backend/PageLayoutHeader.php +++ b/Classes/Backend/PageLayoutHeader.php @@ -117,12 +117,18 @@ protected function toolbarIsEnabledForUser(): bool $isEnabled = false; } - if ($this->backendUser->user['quickedit_disableToolbar']) { + if ( + array_key_exists('quickedit_disableToolbar', $this->backendUser->user) && + $this->backendUser->user['quickedit_disableToolbar'] + ) { $isEnabled = false; } foreach ($this->backendUser->userGroups as $group) { - if ($group['quickedit_disableToolbar']) { + if ( + array_key_exists('quickedit_disableToolbar', $group) && + $group['quickedit_disableToolbar'] + ) { $isEnabled = false; } } @@ -235,6 +241,11 @@ protected function prepareFieldsList(string $fields): string $fieldsArray = array_map('trim', $fieldsArray); foreach ($fieldsArray as $index => $field) { + if ($this->isFieldDefined($field) === false) { + unset($fieldsArray[$index]); + continue; + } + if ($this->userHasAccessToField($field) === false || $this->fieldIsAvailableForLanguage($field) === false) { unset($fieldsArray[$index]); @@ -346,4 +357,15 @@ protected function isVisible(): bool return $isVisible; } + + + + /** + * @param string $field + * @return bool + */ + protected function isFieldDefined(string $field): bool + { + return array_key_exists($field, $GLOBALS['TCA']['pages']['columns']); + } } diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 95fdcea..b2c66f7 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ Version 0.2.2 ------------- - Fix php warning by accessing non existing array keys (https://github.com/punktDe/quickedit/issues/15) +- Further code improvements Version 0.2.1 ------------- From 81692b561ed5e6c71feb34f75e93e10490452463 Mon Sep 17 00:00:00 2001 From: Alexander Boehm Date: Mon, 14 Nov 2022 07:41:58 +0100 Subject: [PATCH 4/4] [FIX] Readme.md example code --- Documentation/Changelog/Index.rst | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index b2c66f7..4521755 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -11,6 +11,7 @@ Version 0.2.2 - Fix php warning by accessing non existing array keys (https://github.com/punktDe/quickedit/issues/15) - Further code improvements +- Update README.md example code (https://github.com/punktDe/quickedit/issues/19) Version 0.2.1 ------------- diff --git a/README.md b/README.md index 8749252..c1fb76d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ mod { } 2 { label = Special - fields = slug, suergroup, hidden + fields = slug, hidden, fe_group previewFields = * } }