Commit 56c0bfd7 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[TASK] Replace access to global request in extbase controllers

Since #94428, the extbase Request implements the
PSR-7 ServerRequestInterface. Therefore, all usages
of $GLOBALS['TYPO3_REQUEST'] in core extbase
controllers are now replaced by accessing the extbase
Request object instead.

Since the extbase RequestInterface does not yet
extend the PSR-7 ServerRequestInterface, as this
would be a breaking change, the property type
annotation of $request is changed to the specifc
Request implementation, to still allow IDE support.

Resolves: #94448
Related: #94428
Releases: master
Change-Id: Icc8697993eae55766c21bc98d0e1e222d974ebfc
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69674


Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 0943a9c5
......@@ -107,7 +107,7 @@ class BackendLogController extends ActionController
]);
if ($layout === 'Default') {
$moduleTemplate = $this->moduleTemplateFactory->create($GLOBALS['TYPO3_REQUEST']);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setTitle(LocalizationUtility::translate('LLL:EXT:belog/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'));
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
......
......@@ -16,7 +16,6 @@
namespace TYPO3\CMS\Beuser\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Authentication\PasswordReset;
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
......@@ -118,7 +117,7 @@ class BackendUserController extends ActionController
public function initializeAction(): void
{
$this->moduleData = ModuleData::fromUc((array)($this->getBackendUser()->getModuleData('tx_beuser')));
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->getRequest());
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$this->moduleTemplate->setTitle(LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'));
}
......@@ -187,7 +186,7 @@ class BackendUserController extends ActionController
->setTitle(LocalizationUtility::translate('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral'))
->setHref($this->backendUriBuilder->buildUriFromRoute('record_edit', [
'edit' => ['be_users' => [0 => 'new']],
'returnUrl' => $this->getRequest()->getAttribute('normalizedParams')->getRequestUri()
'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri()
]));
$buttonBar->addButton($addUserButton);
$shortcutButton = $buttonBar->makeShortcutButton()
......@@ -252,7 +251,7 @@ class BackendUserController extends ActionController
->setTitle(LocalizationUtility::translate('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
->setHref($this->backendUriBuilder->buildUriFromRoute('record_edit', [
'edit' => ['be_users' => [$uid => 'edit']],
'returnUrl' => $this->getRequest()->getAttribute('normalizedParams')->getRequestUri()
'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri()
]));
$buttonBar->addButton($editButton);
$addUserButton = $buttonBar->makeLinkButton()
......@@ -260,7 +259,7 @@ class BackendUserController extends ActionController
->setTitle(LocalizationUtility::translate('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral'))
->setHref($this->backendUriBuilder->buildUriFromRoute('record_edit', [
'edit' => ['be_users' => [0 => 'new']],
'returnUrl' => $this->getRequest()->getAttribute('normalizedParams')->getRequestUri()
'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri()
]));
$buttonBar->addButton($addUserButton);
$shortcutButton = $buttonBar->makeShortcutButton()
......@@ -331,7 +330,7 @@ class BackendUserController extends ActionController
);
} else {
GeneralUtility::makeInstance(PasswordReset::class)->initiateReset(
$this->getRequest(),
$this->request,
$context,
$user->getEmail()
);
......@@ -432,7 +431,7 @@ class BackendUserController extends ActionController
->setTitle(LocalizationUtility::translate('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral'))
->setHref($this->backendUriBuilder->buildUriFromRoute('record_edit', [
'edit' => ['be_groups' => [0 => 'new']],
'returnUrl' => $this->getRequest()->getAttribute('normalizedParams')->getRequestUri()
'returnUrl' => $this->request->getAttribute('normalizedParams')->getRequestUri()
]));
$buttonBar->addButton($addGroupButton);
$shortcutButton = $buttonBar->makeShortcutButton()
......@@ -605,15 +604,4 @@ class BackendUserController extends ActionController
{
return $GLOBALS['BE_USER'];
}
/**
* This is a temporary hack to receive the PSR-7 request until extbase
* provides a PSR-7 compatible request in actions.
*
* @return ServerRequestInterface
*/
protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
......@@ -38,6 +38,7 @@ use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\View\GenericViewResolver;
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
......@@ -128,7 +129,8 @@ abstract class ActionController implements ControllerInterface
/**
* The current request.
*
* @var RequestInterface
* @var Request
* @todo v12: Change @var to RequestInterface, when RequestInterface extends ServerRequestInterface
*/
protected $request;
......@@ -443,6 +445,7 @@ abstract class ActionController implements ControllerInterface
*/
public function processRequest(RequestInterface $request): ResponseInterface
{
/** @var Request $request */
$this->request = $request;
// @deprecated since v11, will be removed in v12.
$this->request->setDispatched(true);
......
......@@ -20,6 +20,8 @@ use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
/**
* Contract for an extbase request.
*
* @todo v12: interface RequestInterface extends ServerRequestInterface
*/
interface RequestInterface
{
......
......@@ -523,7 +523,7 @@ class FormManagerController extends AbstractBackendController
// Reload
$reloadButton = $buttonBar->makeLinkButton()
->setHref($GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri())
->setHref($this->request->getAttribute('normalizedParams')->getRequestUri())
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
$buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
......
......@@ -16,7 +16,6 @@
namespace TYPO3\CMS\IndexedSearch\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
......@@ -162,7 +161,7 @@ class AdministrationController extends ActionController
*/
public function initializeAction()
{
$this->pageUid = (int)($this->getServerRequest()->getQueryParams()['id'] ?? 0);
$this->pageUid = (int)($this->request->getQueryParams()['id'] ?? 0);
$this->indexerConfig = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('indexed_search');
$this->enableMetaphoneSearch = (bool)$this->indexerConfig['enableMetaphoneSearch'];
$this->indexer = GeneralUtility::makeInstance(Indexer::class);
......@@ -564,18 +563,4 @@ class AdministrationController extends ActionController
{
return $GLOBALS['LANG'];
}
/**
* We currently rely on the PSR-7 request next to the extbase specific
* implementation, since we have to access non-prefixed query arguments.
* See initializeAction(), which fetches the `id` (UID of the selected
* page in the page tree).
*
* @return ServerRequestInterface
* @todo Remove as soon as extbase uses the PSR-7 request
*/
protected function getServerRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment