Skip to content

Commit

Permalink
[TASK] Make use of PSR-7 request object in BE Template module
Browse files Browse the repository at this point in the history
Switch from GeneralUtility::_GP() to PSR-7 in EXT:tstemplate.

All occurrences are replaced by proper Object-Oriented coding.

Resolves: #88582
Releases: master
Change-Id: I4cb94601f1c6bbe62025f40f92154f40ec051ce8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60993
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
bmack authored and andreaskienast committed Jul 5, 2019
1 parent bcdd1ab commit 11d6281
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 157 deletions.
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
Expand Down Expand Up @@ -54,20 +55,27 @@ class TemplateAnalyzerModuleFunctionController
*/
protected $id;

/**
* @var ServerRequestInterface
*/
protected $request;

/**
* Init, called from parent object
*
* @param TypoScriptTemplateModuleController $pObj
* @param ServerRequestInterface $request
*/
public function init($pObj)
public function init($pObj, ServerRequestInterface $request)
{
$this->pObj = $pObj;
$this->request = $request;

// Setting MOD_MENU items as we need them for logging:
$this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->modMenu());
$this->localLanguageFilePath = 'EXT:tstemplate/Resources/Private/Language/locallang_analyzer.xlf';
$this->pObj->modMenu_setDefaultList .= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
$this->id = (int)GeneralUtility::_GP('id');
$this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
}

/**
Expand Down Expand Up @@ -123,7 +131,7 @@ public function main()

$assigns = [];
$template_uid = 0;
$assigns['manyTemplatesMenu'] = $this->pObj->templateMenu();
$assigns['manyTemplatesMenu'] = $this->pObj->templateMenu($this->request);
$assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':';
if ($assigns['manyTemplatesMenu']) {
$template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
Expand Down Expand Up @@ -155,7 +163,7 @@ public function main()
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$assigns['moduleLink'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters);

$assigns['template'] = $template = GeneralUtility::_GET('template');
$assigns['template'] = $template = ($this->request->getQueryParams()['template'] ?? null);
$addParams = $template ? '&template=' . $template : '';
$assigns['checkboxes'] = [
'ts_analyzer_checkLinenum' => [
Expand Down
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand Down Expand Up @@ -56,15 +57,22 @@ class TypoScriptTemplateConstantEditorModuleFunctionController
*/
protected $id;

/**
* @var ServerRequestInterface
*/
protected $request;

/**
* Init, called from parent object
*
* @param TypoScriptTemplateModuleController $pObj A reference to the parent (calling) object
* @param ServerRequestInterface $request
*/
public function init($pObj)
public function init($pObj, ServerRequestInterface $request)
{
$this->pObj = $pObj;
$this->id = (int)GeneralUtility::_GP('id');
$this->request = $request;
$this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
}

/**
Expand Down Expand Up @@ -113,7 +121,7 @@ public function main()
// Create extension template
$this->pObj->createTemplate($this->id);
// Checking for more than one template an if, set a menu...
$manyTemplatesMenu = $this->pObj->templateMenu();
$manyTemplatesMenu = $this->pObj->templateMenu($this->request);
$template_uid = 0;
if ($manyTemplatesMenu) {
$template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
Expand All @@ -130,9 +138,9 @@ public function main()

$saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid'];
// Update template ?
if (GeneralUtility::_POST('_savedok')) {
if ($this->request->getParsedBody()['_savedok'] ?? false) {
$this->templateService->changed = 0;
$this->templateService->ext_procesInput(GeneralUtility::_POST(), [], $this->constants, $this->templateRow);
$this->templateService->ext_procesInput($this->request->getParsedBody(), [], $this->constants, $this->templateRow);
if ($this->templateService->changed) {
// Set the data to be saved
$recData = [];
Expand All @@ -150,7 +158,7 @@ public function main()
}
// Resetting the menu (start). I wonder if this in any way is a violation of the menu-system. Haven't checked. But need to do it here, because the menu is dependent on the categories available.
$this->pObj->MOD_MENU['constant_editor_cat'] = $this->templateService->ext_getCategoryLabelArray();
$this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), 'web_ts');
$this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, $this->request->getParsedBody()['SET'] ?? $this->request->getQueryParams()['SET'] ?? [], 'web_ts');
// Resetting the menu (stop)
$assigns['title'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], 'constants');
if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -48,15 +49,22 @@ class TypoScriptTemplateInformationModuleFunctionController
*/
protected $id;

/**
* @var ServerRequestInterface
*/
protected $request;

/**
* Init, called from parent object
*
* @param TypoScriptTemplateModuleController $pObj A reference to the parent (calling) object
* @param ServerRequestInterface $request
*/
public function init($pObj)
public function init($pObj, ServerRequestInterface $request)
{
$this->pObj = $pObj;
$this->id = (int)GeneralUtility::_GP('id');
$this->request = $request;
$this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
}

/**
Expand Down Expand Up @@ -123,7 +131,7 @@ protected function initialize_editor($pageId, $template_uid = 0)
public function main()
{
// Checking for more than one template an if, set a menu...
$manyTemplatesMenu = $this->pObj->templateMenu();
$manyTemplatesMenu = $this->pObj->templateMenu($this->request);
$template_uid = 0;
if ($manyTemplatesMenu) {
$template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage'];
Expand All @@ -137,7 +145,7 @@ public function main()
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
// Create extension template
$newId = $this->pObj->createTemplate($this->id, $saveId);
$newId = $this->pObj->createTemplate($this->id, (int)$saveId);
if ($newId) {
// Switch to new template
$urlParameters = [
Expand Down

0 comments on commit 11d6281

Please sign in to comment.