From a4d92d0c5e467c83c4a5c6470a2d1fb89fbad320 Mon Sep 17 00:00:00 2001 From: Christian Kuhn Date: Sun, 20 Jan 2019 12:55:15 +0100 Subject: [PATCH] [TASK] Add feedit specific code from ext:adminpanel --- Classes/Modules/EditModule.php | 148 ++++++++++++++++++ Resources/Private/Language/locallang_edit.xlf | 21 +++ Resources/Private/Partials/Form/Checkbox.html | 13 ++ .../Templates/Modules/Settings/Edit.html | 16 ++ Resources/Public/JavaScript/Modules/Edit.js | 24 +++ ext_localconf.php | 5 + 6 files changed, 227 insertions(+) create mode 100644 Classes/Modules/EditModule.php create mode 100644 Resources/Private/Language/locallang_edit.xlf create mode 100644 Resources/Private/Partials/Form/Checkbox.html create mode 100644 Resources/Private/Templates/Modules/Settings/Edit.html create mode 100644 Resources/Public/JavaScript/Modules/Edit.js diff --git a/Classes/Modules/EditModule.php b/Classes/Modules/EditModule.php new file mode 100644 index 0000000..cf67ad7 --- /dev/null +++ b/Classes/Modules/EditModule.php @@ -0,0 +1,148 @@ +createToolbar(); + $view = GeneralUtility::makeInstance(StandaloneView::class); + $templateNameAndPath = 'EXT:feedit/Resources/Private/Templates/Modules/Settings/Edit.html'; + $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath)); + $view->setPartialRootPaths(['EXT:feedit/Resources/Private/Partials']); + $view->assignMultiple( + [ + 'display' => [ + 'fieldIcons' => $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons'), + 'displayIcons' => $this->configurationService->getConfigurationOption('edit', 'displayIcons'), + ], + 'toolbar' => $toolbar, + 'script' => [ + 'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'], + 'pageModule' => $this->getPageModule(), + 'backendScript' => BackendUtility::getBackendScript(), + 't3BeSitenameMd5' => md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']), + ], + ] + ); + return $view->render(); + } + + /** + * @return TypoScriptFrontendController + */ + protected function getTypoScriptFrontendController(): TypoScriptFrontendController + { + return $GLOBALS['TSFE']; + } + + /** + * @return string + */ + private function getPageModule(): string + { + $pageModule = trim($this->getBackendUser()->getTSConfig()['options.']['overridePageModule'] ?? ''); + return BackendUtility::isModuleSetInTBE_MODULES($pageModule) ? $pageModule : 'web_layout'; + } + + /** + * @inheritdoc + */ + public function getIdentifier(): string + { + return 'edit'; + } + + /** + * @inheritdoc + */ + public function getIconIdentifier(): string + { + return 'actions-open'; + } + + /** + * @inheritdoc + */ + public function getLabel(): string + { + $locallangFileAndPath = 'LLL:EXT:feedit/Resources/Private/Language/locallang_edit.xlf:module.label'; + return $this->getLanguageService()->sL($locallangFileAndPath); + } + + /** + * Initialize the edit module + * Includes the frontend edit initialization + * + * @param ServerRequestInterface $request + */ + public function initializeModule(ServerRequestInterface $request): void + { + $typoScriptFrontend = $this->getTypoScriptFrontendController(); + $typoScriptFrontend->displayEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayIcons'); + $typoScriptFrontend->displayFieldEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons'); + + if ($request->getQueryParams()['ADMCMD_editIcons'] ?? $request->getParsedBody()['ADMCMD_editIcons'] ?? false) { + $typoScriptFrontend->displayFieldEditIcons = '1'; + } + if ($typoScriptFrontend->displayEditIcons) { + $typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true); + } + if ($typoScriptFrontend->displayFieldEditIcons) { + $typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true); + } + } + + /** + * @return array + */ + public function getJavaScriptFiles(): array + { + return ['EXT:feedit/Resources/Public/JavaScript/Modules/Edit.js']; + } + + /** + * Returns a string array with css files that will be rendered after the module + * + * @return array + */ + public function getCssFiles(): array + { + return []; + } +} diff --git a/Resources/Private/Language/locallang_edit.xlf b/Resources/Private/Language/locallang_edit.xlf new file mode 100644 index 0000000..3e00082 --- /dev/null +++ b/Resources/Private/Language/locallang_edit.xlf @@ -0,0 +1,21 @@ + + + +
+ + + Edit + + + Display edit icons + + + Display edit panels + + + Open TYPO3 Backend + + + + diff --git a/Resources/Private/Partials/Form/Checkbox.html b/Resources/Private/Partials/Form/Checkbox.html new file mode 100644 index 0000000..74e5c09 --- /dev/null +++ b/Resources/Private/Partials/Form/Checkbox.html @@ -0,0 +1,13 @@ + + +
+
+ + + +
+
+
+ diff --git a/Resources/Private/Templates/Modules/Settings/Edit.html b/Resources/Private/Templates/Modules/Settings/Edit.html new file mode 100644 index 0000000..6e68f49 --- /dev/null +++ b/Resources/Private/Templates/Modules/Settings/Edit.html @@ -0,0 +1,16 @@ + + + +{toolbar} + + diff --git a/Resources/Public/JavaScript/Modules/Edit.js b/Resources/Public/JavaScript/Modules/Edit.js new file mode 100644 index 0000000..0fee2e8 --- /dev/null +++ b/Resources/Public/JavaScript/Modules/Edit.js @@ -0,0 +1,24 @@ +function editModuleOnClickHandler(event) { + event.preventDefault(); + var element = event.target; + if (parent.opener && parent.opener.top) { + parent.opener.top.fsMod.recentIds['web'] = element.getAttribute('data-pageUid'); + if (parent.opener.top && parent.opener.top.nav_frame && parent.opener.top.nav_frame.refresh_nav) { + parent.opener.top.nav_frame.refresh_nav(); + } + parent.opener.top.goToModule(element.getAttribute('data-pageModule')); + parent.opener.top.focus(); + } else { + var vHWin = window.open(element.getAttribute('data-backendScript'), element.getAttribute('data-t3BeSitenameMd5')); + vHWin.focus(); + } + return false; +} + +function initializeEditModule() { + var editModuleBtnOpenBackend = document.querySelector('.typo3-adminPanel-btn-openBackend'); + editModuleBtnOpenBackend.addEventListener('click', editModuleOnClickHandler); +} + + +window.addEventListener('load', initializeEditModule, false); diff --git a/ext_localconf.php b/ext_localconf.php index 943ffcd..bf9b009 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,3 +3,8 @@ defined('TYPO3_MODE') or die(); // Register the edit panel view. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'] = \TYPO3\CMS\Feedit\FrontendEditPanel::class; + +$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']['edit'] = [ + 'module' => \TYPO3\CMS\Feedit\Modules\EditModule::class, + 'after' => ['cache'], +]; \ No newline at end of file