Skip to content

Commit

Permalink
[TASK] Drop remaining _GP and getIndpEnv in ContentElement/ElementHis…
Browse files Browse the repository at this point in the history
…toryController

Also pass around request object internally instead of storing it as property.

Change-Id: Idac5aaab8817225451cf59d2e677218033e6b2fb
Resolves: #84388
Releases: master
Reviewed-on: https://review.typo3.org/56283
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 17, 2018
1 parent 19aa3b4 commit f7ef126
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
*/
class ElementHistoryController
{
/**
* @var ServerRequestInterface
*/
protected $request;

/**
* @var StandaloneView
*/
Expand Down Expand Up @@ -86,13 +81,14 @@ public function __construct()
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->request = $request;
$this->moduleTemplate->getDocHeaderComponent()->setMetaInformation([]);

$lastHistoryEntry = (int)($request->getParsedBody()['historyEntry'] ?: $request->getQueryParams()['historyEntry']);
$rollbackFields = $request->getParsedBody()['rollbackFields'] ?: $request->getQueryParams()['rollbackFields'];
$element = $request->getParsedBody()['element'] ?: $request->getQueryParams()['element'];
$displaySettings = $this->prepareDisplaySettings();
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$lastHistoryEntry = (int)($parsedBody['historyEntry'] ?? $queryParams['historyEntry'] ?? 0);
$rollbackFields = $parsedBody['rollbackFields'] ?? $queryParams['rollbackFields'] ?? null;
$element = $parsedBody['element'] ?? $queryParams['element'] ?? null;
$displaySettings = $this->prepareDisplaySettings($request);
$this->view->assign('currentSelection', $displaySettings);

$this->showDiff = (int)$displaySettings['showDiff'];
Expand Down Expand Up @@ -122,6 +118,8 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
}
}

/** @var \TYPO3\CMS\Core\Http\NormalizedParams $normalizedParams */
$normalizedParams = $request->getAttribute('normalizedParams');
$elementData = $this->historyObject->getElementData();
if ($elementData) {
$this->setPagePath($elementData[0], $elementData[1]);
Expand All @@ -133,16 +131,16 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
$this->view->assign('fullHistoryUrl', $this->buildUrl([
'element' => 'pages:' . $parentPage['pid'],
'historyEntry' => '',
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
'returnUrl' => $normalizedParams->getRequestUri(),
]));
}
}
}

$this->view->assign('TYPO3_REQUEST_URI', GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
$this->view->assign('TYPO3_REQUEST_URI', $normalizedParams->getRequestUrl());

// Setting up the buttons and markers for docheader
$this->getButtons();
$this->getButtons($request);
// Build the <body> for the module
$this->moduleTemplate->setContent($this->view->render());

Expand Down Expand Up @@ -174,8 +172,10 @@ protected function setPagePath($table, $uid)

/**
* Create the panel of buttons for submitting the form or otherwise perform operations.
*
* @param ServerRequestInterface $request
*/
protected function getButtons()
protected function getButtons(ServerRequestInterface $request)
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

Expand All @@ -185,7 +185,10 @@ protected function getButtons()
$buttonBar->addButton($helpButton);

// Get returnUrl parameter
$returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');

if ($returnUrl) {
$backButton = $buttonBar->makeLinkButton()
->setHref($returnUrl)
Expand All @@ -197,19 +200,25 @@ protected function getButtons()

/**
* Displays settings evaluation
*
* @param ServerRequestInterface $request
*/
protected function prepareDisplaySettings()
protected function prepareDisplaySettings(ServerRequestInterface $request)
{
// Get current selection from UC, merge data, write it back to UC
$currentSelection = is_array($this->getBackendUser()->uc['moduleData']['history'])
? $this->getBackendUser()->uc['moduleData']['history']
: ['maxSteps' => '', 'showDiff' => 1, 'showSubElements' => 1];
$currentSelectionOverride = $this->request->getParsedBody()['settings'] ? $this->request->getParsedBody()['settings'] : $this->request->getQueryParams()['settings'];
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$currentSelectionOverride = $parsedBody['settings'] ?? $queryParams['settings'] ?? null;

if (is_array($currentSelectionOverride) && !empty($currentSelectionOverride)) {
$currentSelection = array_merge($currentSelection, $currentSelectionOverride);
$this->getBackendUser()->uc['moduleData']['history'] = $currentSelection;
$this->getBackendUser()->writeUC($this->getBackendUser()->uc);
}

// Display selector for number of history entries
$selector['maxSteps'] = [
10 => [
Expand Down

0 comments on commit f7ef126

Please sign in to comment.