From ef7fb4a4991fc801cebd91089f93b30305b86de5 Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Wed, 15 Aug 2018 22:19:07 +0200 Subject: [PATCH] [TASK] Clean up FrontendEditing Controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The FrontendEditingController class in EXT:core does two things: - persisting incoming GET/POST requests (actually only when EXT:feedit is installed) - rendering editIcons and editIconPanel In order to separate these concerns, the first patch extracts some minor functionality into EXT:feedit, and cleans up code which should have been done long ago. The next iteration will be to deprecate unused methods and properties, and to move FrontendEditingController into EXT:feedit, however, using an Interface to render editIcons and editPanels instead. Resolves: #85869 Releases: master Change-Id: I78ed1da9e619099dc56b970961c90c34f8dff1e4 Reviewed-on: https://review.typo3.org/57925 Tested-by: TYPO3com Reviewed-by: Frank Naegler Tested-by: Frank Naegler Reviewed-by: Wouter Wolters Reviewed-by: Jörg Bösche Reviewed-by: Andreas Fernandez Tested-by: Andreas Fernandez --- Classes/Middleware/FrontendEditInitiator.php | 38 +++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/Classes/Middleware/FrontendEditInitiator.php b/Classes/Middleware/FrontendEditInitiator.php index d2f886b..4a16f54 100644 --- a/Classes/Middleware/FrontendEditInitiator.php +++ b/Classes/Middleware/FrontendEditInitiator.php @@ -54,11 +54,16 @@ class FrontendEditInitiator implements MiddlewareInterface } else { $controllerKey = 'default'; } - $controllerClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey]; - if ($controllerClass) { - $GLOBALS['BE_USER']->frontendEdit = GeneralUtility::makeInstance($controllerClass); - if ($controllerClass instanceof FrontendEditingController) { - $GLOBALS['BE_USER']->frontendEdit->initConfigOptions(); + $controllerClassName = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey] ?? ''; + if (!empty($controllerClassName)) { + $frontendEditingController = GeneralUtility::makeInstance($controllerClassName); + $GLOBALS['BE_USER']->frontendEdit = $frontendEditingController; + if ($GLOBALS['BE_USER']->frontendEdit instanceof FrontendEditingController) { + $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT = $request->getParsedBody()['TSFE_EDIT'] ?? $request->getQueryParams()['TSFE_EDIT'] ?? null; + // Include classes for editing IF editing module in Admin Panel is open + if (((int)$GLOBALS['TSFE']->displayEditIcons === 1 || (int)$GLOBALS['TSFE']->displayFieldEditIcons === 1) && $this->isValidEditAction($GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT)) { + $GLOBALS['BE_USER']->frontendEdit->editAction(); + } } } break; @@ -68,4 +73,27 @@ class FrontendEditInitiator implements MiddlewareInterface } return $handler->handle($request); } + + /** + * Returns TRUE if an edit-action is sent from the Admin Panel + * + * @param array|null $parameters + * @return bool + */ + protected function isValidEditAction(array &$parameters = null): bool + { + if (!is_array($parameters)) { + return false; + } + if ($parameters['cancel']) { + unset($parameters['cmd']); + } else { + $cmd = (string)$parameters['cmd']; + if (($cmd !== 'edit' || is_array($parameters['data']) && ($parameters['doSave'] || $parameters['update'] || $parameters['update_close'])) && $cmd !== 'new') { + // $cmd can be a command like "hide" or "move". If $cmd is "edit" or "new" it's an indication to show the formfields. But if data is sent with update-flag then $cmd = edit is accepted because edit may be sent because of .keepGoing flag. + return true; + } + } + return false; + } }