mirror of
https://github.com/FriendsOfTYPO3/feedit.git
synced 2024-11-22 22:36:08 +01:00
ef7fb4a499
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 <no-reply@typo3.com> Reviewed-by: Frank Naegler <frank.naegler@typo3.org> Tested-by: Frank Naegler <frank.naegler@typo3.org> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Jörg Bösche <typo3@joergboesche.de> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
99 lines
4.6 KiB
PHP
99 lines
4.6 KiB
PHP
<?php
|
|
declare(strict_types = 1);
|
|
|
|
namespace TYPO3\CMS\Feedit\Middleware;
|
|
|
|
/*
|
|
* This file is part of the TYPO3 CMS project.
|
|
*
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, either version 2
|
|
* of the License, or any later version.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*
|
|
* The TYPO3 project - inspiring people to share!
|
|
*/
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
|
|
use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
|
|
|
/**
|
|
* PSR-15 middleware initializing frontend editing
|
|
*/
|
|
class FrontendEditInitiator implements MiddlewareInterface
|
|
{
|
|
|
|
/**
|
|
* Process an incoming server request and return a response, optionally delegating
|
|
* response creation to a handler.
|
|
*
|
|
* @param ServerRequestInterface $request
|
|
* @param RequestHandlerInterface $handler
|
|
* @return ResponseInterface
|
|
*/
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
{
|
|
if (isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) {
|
|
$config = $GLOBALS['BE_USER']->getTSConfig()['admPanel.'] ?? [];
|
|
$active = (int)$GLOBALS['TSFE']->displayEditIcons === 1 || (int)$GLOBALS['TSFE']->displayFieldEditIcons === 1;
|
|
if ($active && isset($config['enable.'])) {
|
|
foreach ($config['enable.'] as $value) {
|
|
if ($value) {
|
|
if ($GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
|
|
// Grab the Page TSConfig property that determines which controller to use.
|
|
$pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
|
|
$controllerKey = $pageTSConfig['TSFE.']['frontendEditingController'] ?? 'default';
|
|
} else {
|
|
$controllerKey = 'default';
|
|
}
|
|
$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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|