diff --git a/Classes/Middleware/FrontendEditInitiator.php b/Classes/Middleware/FrontendEditInitiator.php index c50fef6..6a1c792 100644 --- a/Classes/Middleware/FrontendEditInitiator.php +++ b/Classes/Middleware/FrontendEditInitiator.php @@ -20,9 +20,11 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use TYPO3\CMS\Adminpanel\Service\ConfigurationService; use TYPO3\CMS\Backend\FrontendBackendUserAuthentication; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Feedit\DataHandling\FrontendEditDataHandler; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** * PSR-15 middleware initializing frontend editing @@ -43,6 +45,11 @@ class FrontendEditInitiator implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if (isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) { + $this->initializeTypoScriptFrontend( + $GLOBALS['TSFE'], + $request, + GeneralUtility::makeInstance(ConfigurationService::class) + ); $config = $GLOBALS['BE_USER']->getTSConfig()['admPanel.'] ?? []; $active = (int)$GLOBALS['TSFE']->displayEditIcons === 1 || (int)$GLOBALS['TSFE']->displayFieldEditIcons === 1; // Include classes for editing IF editing module in Admin Panel is open @@ -83,4 +90,23 @@ class FrontendEditInitiator implements MiddlewareInterface } return false; } + + protected function initializeTypoScriptFrontend( + TypoScriptFrontendController $typoScriptFrontend, + ServerRequestInterface $request, + ConfigurationService $configurationService + ): void { + $typoScriptFrontend->displayEditIcons = $configurationService->getConfigurationOption('edit', 'displayIcons'); + $typoScriptFrontend->displayFieldEditIcons = $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); + } + } } diff --git a/Classes/Modules/EditModule.php b/Classes/Modules/EditModule.php index cf67ad7..67c86f0 100644 --- a/Classes/Modules/EditModule.php +++ b/Classes/Modules/EditModule.php @@ -21,9 +21,10 @@ use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule; use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface; use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface; use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface; -use TYPO3\CMS\Adminpanel\Service\EditToolbarService; +use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Feedit\Service\EditToolbarService; use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -32,6 +33,20 @@ use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; */ class EditModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface { + /** + * @var UriBuilder + */ + protected $uriBuilder; + + /** + * @param UriBuilder $uriBuilder + */ + public function __construct(UriBuilder $uriBuilder) + { + parent::__construct(); + $this->uriBuilder = $uriBuilder; + } + /** * Creates the content for the "edit" section ("module") of the Admin Panel * @@ -53,9 +68,12 @@ class EditModule extends AbstractModule implements PageSettingsProviderInterface ], 'toolbar' => $toolbar, 'script' => [ - 'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'], - 'pageModule' => $this->getPageModule(), - 'backendScript' => BackendUtility::getBackendScript(), + 'backendScript' => $this->uriBuilder->buildUriFromRoute( + 'web_layout', + [ + 'id' => (int)$this->getTypoScriptFrontendController()->page['uid'], + ] + ), 't3BeSitenameMd5' => md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']), ], ] @@ -113,19 +131,6 @@ class EditModule extends AbstractModule implements PageSettingsProviderInterface */ 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); - } } /** diff --git a/Classes/Service/EditToolbarService.php b/Classes/Service/EditToolbarService.php new file mode 100644 index 0000000..94d387f --- /dev/null +++ b/Classes/Service/EditToolbarService.php @@ -0,0 +1,293 @@ +-tags linking them to proper functions. + */ + public function createToolbar(): string + { + /** @var LanguageAspect $languageAspect */ + $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language'); + $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'; + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); + $perms = $this->getBackendUser()->calcPerms($tsfe->page); + $langAllowed = $this->getBackendUser()->checkLanguageAccess($languageAspect->getId()); + $id = $tsfe->id; + $returnUrl = GeneralUtility::getIndpEnv('REQUEST_URI'); + $classes = 'typo3-adminPanel-btn typo3-adminPanel-btn-default typo3-adminPanel-btn-openBackend'; + $output = []; + $output[] = '