From 5b7ddfc36674c88d07a9ac79165613349f538c56 Mon Sep 17 00:00:00 2001 From: Georg Ringer Date: Thu, 29 Dec 2022 09:22:43 +0100 Subject: [PATCH] [TASK] Support v11 + v12 --- .../ContentObject/EditPanelContentObject.php | 43 ++++++++++ .../DataHandling/FrontendEditDataHandler.php | 9 +- Classes/FrontendEditPanel.php | 84 ++++++++++--------- Classes/Hooks/StdWrapEditPanelHook.php | 62 ++++++++++++++ Classes/Middleware/FrontendEditInitiator.php | 6 +- Classes/Modules/EditModule.php | 1 - Classes/Service/EditToolbarService.php | 2 +- Configuration/Services.yaml | 8 ++ Configuration/TCA/Overrides/sys_template.php | 1 - composer.json | 8 +- ext_emconf.php | 7 +- ext_localconf.php | 9 +- 12 files changed, 179 insertions(+), 61 deletions(-) create mode 100755 Classes/ContentObject/EditPanelContentObject.php create mode 100644 Classes/Hooks/StdWrapEditPanelHook.php diff --git a/Classes/ContentObject/EditPanelContentObject.php b/Classes/ContentObject/EditPanelContentObject.php new file mode 100755 index 0000000..6622253 --- /dev/null +++ b/Classes/ContentObject/EditPanelContentObject.php @@ -0,0 +1,43 @@ +isBackendUserLoggedIn()) { + $theValue = $this->cObj->editPanel($theValue, $conf); + } + if (isset($conf['stdWrap.'])) { + $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']); + } + return $theValue; + } +} diff --git a/Classes/DataHandling/FrontendEditDataHandler.php b/Classes/DataHandling/FrontendEditDataHandler.php index 0483b8d..28d2836 100644 --- a/Classes/DataHandling/FrontendEditDataHandler.php +++ b/Classes/DataHandling/FrontendEditDataHandler.php @@ -64,11 +64,12 @@ class FrontendEditDataHandler public function editAction() { // Commands - list($table, $uid) = explode(':', $this->configuration['record']); - $uid = (int)$uid; - $cmd = $this->configuration['cmd']; + $split= explode(':', (string)($this->configuration['record'] ?? '')); + $table = $split[0] ?? ''; + $uid = (int)($split[1] ?? 0); + $cmd = $this->configuration['cmd'] ?? ''; // Look for some configuration data that indicates we should save. - if (($this->configuration['doSave'] || $this->configuration['update'] || $this->configuration['update_close']) && is_array($this->configuration['data'])) { + if ((($this->configuration['doSave'] ?? '') || ($this->configuration['update'] ?? '') || ($this->configuration['update_close'] ?? '')) && is_array($this->configuration['data'] ?? null)) { $cmd = 'save'; } if ($cmd === 'save' || $cmd && $table && $uid && isset($GLOBALS['TCA'][$table])) { diff --git a/Classes/FrontendEditPanel.php b/Classes/FrontendEditPanel.php index eaa4c3e..8aecc1c 100644 --- a/Classes/FrontendEditPanel.php +++ b/Classes/FrontendEditPanel.php @@ -1,4 +1,5 @@ frontendController = $frontendController ?: $GLOBALS['TSFE']; $this->backendUser = $backendUser ?: $GLOBALS['BE_USER']; - $this->cObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); - $this->cObj->start([]); + # $this->cObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); + # $this->cObj->start([]); + $this->cObj = $contentObjectRenderer; $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_tsfe.xlf'); } @@ -111,7 +113,7 @@ class FrontendEditPanel } if (isset($allow['edit'])) { $icon = '' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render('inline') . ''; - $panel .= $this->editPanelLinkWrap($icon, $formName, 'edit', $dataArr['_LOCALIZED_UID'] ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord); + $panel .= $this->editPanelLinkWrap($icon, $formName, 'edit', isset($dataArr['_LOCALIZED_UID']) ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord); } // Hiding in workspaces because implementation is incomplete if (isset($allow['move']) && $sortField && $this->backendUser->workspace === 0) { @@ -122,7 +124,7 @@ class FrontendEditPanel } // Hiding in workspaces because implementation is incomplete // Hiding for localizations because it is unknown what should be the function in that case - if (isset($allow['hide']) && $hideField && $this->backendUser->workspace === 0 && !$dataArr['_LOCALIZED_UID']) { + if (isset($allow['hide']) && $hideField && $this->backendUser->workspace === 0 && !($dataArr['_LOCALIZED_UID'] ?? 0)) { if ($dataArr[$hideField]) { $icon = $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render('inline'); $panel .= $this->editPanelLinkWrap($icon, $formName, 'unhide'); @@ -146,14 +148,16 @@ class FrontendEditPanel } // Hiding in workspaces because implementation is incomplete // Hiding for localizations because it is unknown what should be the function in that case - if (isset($allow['delete']) && $this->backendUser->workspace === 0 && !$dataArr['_LOCALIZED_UID']) { + if (isset($allow['delete']) && $this->backendUser->workspace === 0 && !($dataArr['_LOCALIZED_UID'] ?? 0)) { $icon = '' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render('inline') . ''; $panel .= $this->editPanelLinkWrap($icon, $formName, 'delete', '', $this->getLabel('p_deleteConfirm')); } + // Final - $labelTxt = $this->cObj->stdWrap($conf['label'], $conf['label.']); +// $labelTxt = $this->cObj->stdWrap($conf['label'] ?? '', $conf['label.'] ?? []); + $labelTxt = ''; foreach ((array)$hiddenFields as $name => $value) { $hiddenFieldString .= '' . LF; } @@ -163,37 +167,37 @@ class FrontendEditPanel
' - . '
' - . $panel - . '
' . + . '
' + . $panel + . '
' . ($labelTxt ? '
' . sprintf($labelTxt, htmlspecialchars(GeneralUtility::fixed_lgd_cs($dataArr[$labelField], 50))) . '
' : '') . '
'; - // Wrap the panel - if ($conf['innerWrap']) { - $panel = $this->cObj->wrap($panel, $conf['innerWrap']); - } - if ($conf['innerWrap.']) { - $panel = $this->cObj->stdWrap($panel, $conf['innerWrap.']); - } - - // Wrap the complete panel - if ($conf['outerWrap']) { - $panel = $this->cObj->wrap($panel, $conf['outerWrap']); - } - if ($conf['outerWrap.']) { - $panel = $this->cObj->stdWrap($panel, $conf['outerWrap.']); - } - if ($conf['printBeforeContent']) { +// // Wrap the panel +// if ($conf['innerWrap']) { +// $panel = $this->cObj->wrap($panel, $conf['innerWrap']); +// } +// if ($conf['innerWrap.']) { +// $panel = $this->cObj->stdWrap($panel, $conf['innerWrap.']); +// } +// +// // Wrap the complete panel +// if ($conf['outerWrap']) { +// $panel = $this->cObj->wrap($panel, $conf['outerWrap']); +// } +// if ($conf['outerWrap.']) { +// $panel = $this->cObj->stdWrap($panel, $conf['outerWrap.']); +// } + if ($conf['printBeforeContent'] ?? false) { $finalOut = $panel . $content; } else { $finalOut = $content . $panel; } $hidden = $this->isDisabled($table, $dataArr) ? ' typo3-feedit-element-hidden' : ''; - $outerWrapConfig = $conf['stdWrap.'] ?? ['wrap' => '
|
']; - $finalOut = $this->cObj->stdWrap($finalOut, $outerWrapConfig); +// $outerWrapConfig = $conf['stdWrap.'] ?? ['wrap' => '
|
']; +// $finalOut = $this->cObj->stdWrap($finalOut, $outerWrapConfig); return $finalOut; } @@ -213,7 +217,7 @@ class FrontendEditPanel * @param string $fieldList * @return string The input content string, possibly with edit icons added (not necessarily in the end but just after the last string of normal content. */ - public function editIcons($content, $params, array $conf = [], $currentRecord = '', array $dataArr = [], $addUrlParamStr = '', $table, $editUid, $fieldList) + public function editIcons($content, $params, array $conf = [], $currentRecord = '', array $dataArr = [], $addUrlParamStr = '', $table = '', $editUid = 0, $fieldList = '') { // Special content is about to be shown, so the cache must be disabled. $this->frontendController->set_no_cache('Display frontend edit icons', true); @@ -225,15 +229,15 @@ class FrontendEditPanel $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); $url = (string)$uriBuilder->buildUriFromRoute( - 'record_edit', - [ - 'edit[' . $table . '][' . $editUid . ']' => 'edit', - 'columnsOnly' => $fieldList, - 'noView' => $noView, - 'feEdit' => 1, - 'returnUrl' => htmlspecialchars($this->getReturnUrl($editUid)), - ] - ) . $addUrlParamStr; + 'record_edit', + [ + 'edit[' . $table . '][' . $editUid . ']' => 'edit', + 'columnsOnly' => $fieldList, + 'noView' => $noView, + 'feEdit' => 1, + 'returnUrl' => htmlspecialchars($this->getReturnUrl($editUid)), + ] + ) . $addUrlParamStr; $icon = $this->editPanelLinkWrap_doWrap($iconImg, $url, 'content-link'); if ($conf['beforeLastTag'] < 0) { $content = $icon . $content; @@ -413,7 +417,7 @@ class FrontendEditPanel if (is_int($recordUid)) { $uri = new Uri($url); $uri = $uri->withFragment('#c' . $recordUid); - $url = (string) $uri; + $url = (string)$uri; } return $url; diff --git a/Classes/Hooks/StdWrapEditPanelHook.php b/Classes/Hooks/StdWrapEditPanelHook.php new file mode 100644 index 0000000..1288c77 --- /dev/null +++ b/Classes/Hooks/StdWrapEditPanelHook.php @@ -0,0 +1,62 @@ +getFrontendBackendUser(); + if ($user && ($configuration['editPanel'] ?? false) && StateUtility::isOpen() && $configurationService->getConfigurationOption('edit', 'displayIcons')) { + [$table, $uid] = explode(':', $parentObject->currentRecord); + $allowedActions = $user->getAllowedEditActions($table, $configuration['editPanel.'] ?? [], $parentObject->data['pid']); + $frontendEditPanel = GeneralUtility::makeInstance(FrontendEditPanel::class, $parentObject); + return $frontendEditPanel->editPanel( + $content, + $configuration['editPanel.'] ?? [], + $parentObject->currentRecord, + $parentObject->data, + 'tt_content', + $allowedActions + ); + } + return $content; + } + + protected function getFrontendBackendUser() + { + return $GLOBALS['BE_USER']; + } +} \ No newline at end of file diff --git a/Classes/Middleware/FrontendEditInitiator.php b/Classes/Middleware/FrontendEditInitiator.php index 21e10ee..3e63d95 100644 --- a/Classes/Middleware/FrontendEditInitiator.php +++ b/Classes/Middleware/FrontendEditInitiator.php @@ -57,7 +57,7 @@ class FrontendEditInitiator implements MiddlewareInterface if ($active && isset($config['enable.'])) { foreach ($config['enable.'] as $value) { if ($value) { - $parameters = $request->getParsedBody()['TSFE_EDIT'] ?? $request->getQueryParams()['TSFE_EDIT'] ?? null; + $parameters = $request->getParsedBody()['TSFE_EDIT'] ?? $request->getQueryParams()['TSFE_EDIT'] ?? []; if ($this->isValidEditAction($parameters)) { GeneralUtility::makeInstance(FrontendEditDataHandler::class, $parameters)->editAction(); } @@ -80,10 +80,10 @@ class FrontendEditInitiator implements MiddlewareInterface if (!is_array($parameters)) { return false; } - if ($parameters['cancel']) { + if ($parameters['cancel'] ?? false) { unset($parameters['cmd']); } else { - $cmd = (string)$parameters['cmd']; + $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; diff --git a/Classes/Modules/EditModule.php b/Classes/Modules/EditModule.php index d596e2a..9cffdf6 100644 --- a/Classes/Modules/EditModule.php +++ b/Classes/Modules/EditModule.php @@ -44,7 +44,6 @@ class EditModule extends AbstractModule implements PageSettingsProviderInterface */ public function __construct(UriBuilder $uriBuilder) { - parent::__construct(); $this->uriBuilder = $uriBuilder; } diff --git a/Classes/Service/EditToolbarService.php b/Classes/Service/EditToolbarService.php index be78de8..31e185f 100644 --- a/Classes/Service/EditToolbarService.php +++ b/Classes/Service/EditToolbarService.php @@ -50,7 +50,7 @@ class EditToolbarService $iconFactory = GeneralUtility::makeInstance(IconFactory::class); $tsfe = $this->getTypoScriptFrontendController(); // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead: - $moduleName = BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element'; + $moduleName = BackendUtility::getPagesTSconfig($tsfe->page['uid'])['mod.']['newContentElementWizard.']['override'] ?? 'new_content_element_wizard'; $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $perms = $this->getBackendUser()->calcPerms($tsfe->page); $langAllowed = $this->getBackendUser()->checkLanguageAccess($languageAspect->getId()); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 1c9db19..d8d6fe6 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -9,3 +9,11 @@ services: TYPO3\CMS\Feedit\Modules\EditModule: public: true + + TYPO3\CMS\Feedit\Hooks\StdWrapEditPanelHook: + public: false + + TYPO3\CMS\Feedit\ContentObject\EditPanelContentObject: + tags: + - name: frontend.contentobject + identifier: 'EDITPANEL' diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index e8079cc..148bd12 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,5 +1,4 @@ 'friendsof@typo3.org', 'author_company' => '', 'state' => 'stable', - 'createDirs' => '', - 'clearCacheOnLoad' => 0, - 'version' => '10.0.2', + 'clearCacheOnLoad' => true, + 'version' => '11.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '10.0.0-10.9.99', + 'typo3' => '11.5.0-12.2.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/ext_localconf.php b/ext_localconf.php index bf9b009..cfe782f 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,10 +1,13 @@ \TYPO3\CMS\Feedit\Modules\EditModule::class, 'after' => ['cache'], -]; \ No newline at end of file +]; + +$GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects']['EDITPANEL'] + = \TYPO3\CMS\Feedit\ContentObject\EditPanelContentObject::class; \ No newline at end of file