‪TYPO3CMS  9.5
FrontendEditInitiator.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\MiddlewareInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
27 
33 class ‪FrontendEditInitiator implements MiddlewareInterface
34 {
35 
44  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
45  {
46  if (isset(‪$GLOBALS['BE_USER']) && ‪$GLOBALS['BE_USER'] instanceof ‪FrontendBackendUserAuthentication) {
47  $config = ‪$GLOBALS['BE_USER']->getTSConfig()['admPanel.'] ?? [];
48  $active = (int)‪$GLOBALS['TSFE']->displayEditIcons === 1 || (int)‪$GLOBALS['TSFE']->displayFieldEditIcons === 1;
49  // Include classes for editing IF editing module in Admin Panel is open
50  if ($active && isset($config['enable.'])) {
51  foreach ($config['enable.'] as $value) {
52  if ($value) {
53  $parameters = $request->getParsedBody()['TSFE_EDIT'] ?? $request->getQueryParams()['TSFE_EDIT'] ?? null;
54  $isValidEditAction = $this->‪isValidEditAction($parameters);
55  if (‪$GLOBALS['TSFE'] instanceof ‪TypoScriptFrontendController) {
56  // Grab the Page TSConfig property that determines which controller to use.
57  $pageTSConfig = ‪$GLOBALS['TSFE']->getPagesTSconfig();
58  $controllerKey = $pageTSConfig['TSFE.']['frontendEditingController'] ?? 'default';
59  } else {
60  $controllerKey = 'default';
61  }
63  $controllerClassName = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController'][$controllerKey] ?? \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController::class;
64  if (!empty($controllerClassName)) {
66  ‪$GLOBALS['BE_USER']->frontendEdit = GeneralUtility::makeInstance(
67  $controllerClassName,
68  $parameters
69  );
70  }
71  if ($isValidEditAction) {
72  GeneralUtility::makeInstance(FrontendEditDataHandler::class, $parameters)->editAction();
73  }
74  break;
75  }
76  }
77  }
78  }
79  return $handler->handle($request);
80  }
81 
88  protected function ‪isValidEditAction(array &$parameters = null): bool
89  {
90  if (!is_array($parameters)) {
91  return false;
92  }
93  if ($parameters['cancel']) {
94  unset($parameters['cmd']);
95  } else {
96  $cmd = (string)$parameters['cmd'];
97  if (($cmd !== 'edit' || is_array($parameters['data']) && ($parameters['doSave'] || $parameters['update'] || $parameters['update_close'])) && $cmd !== 'new') {
98  // $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.
99  return true;
100  }
101  }
102  return false;
103  }
104 }
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:35
‪TYPO3\CMS\Feedit\DataHandling\FrontendEditDataHandler
Definition: FrontendEditDataHandler.php:35
‪TYPO3\CMS\Feedit\Middleware\FrontendEditInitiator\isValidEditAction
‪bool isValidEditAction(array &$parameters=null)
Definition: FrontendEditInitiator.php:88
‪TYPO3\CMS\Feedit\Middleware
Definition: FrontendEditInitiator.php:4
‪TYPO3\CMS\Feedit\Middleware\FrontendEditInitiator\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: FrontendEditInitiator.php:44
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Feedit\Middleware\FrontendEditInitiator
Definition: FrontendEditInitiator.php:34