Commit 7b1c2497 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Christian Kuhn
Browse files

[TASK] Avoid further usages of ControllerContext methods

This patch avoids further undetected usages of deprecated
methods:

- ControllerContext::getFlashMessageQueue()
- ControllerContext::getUriBuilder()

Those methods have been called on a controller context
instance obtained by the rendering context.

Releases: master
Resolves: #93036
Releates: #93019
Releates: #93016
Change-Id: I0634580479f2a814e2644d35cc25abc1ca411d79
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67075


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 733353c1
......@@ -18,7 +18,9 @@ declare(strict_types=1);
namespace TYPO3\CMS\Backend\ViewHelpers;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
......@@ -63,8 +65,17 @@ class ModuleLayoutViewHelper extends AbstractViewHelper
throw new Exception('ModuleLayoutViewHelper can only be used once per module.', 1483292643);
}
$extensionService = GeneralUtility::makeInstance(ExtensionService::class);
$pluginNamespace = $extensionService->getPluginNamespace(
$renderingContext->getRequest()->getControllerExtensionName(),
$renderingContext->getRequest()->getPluginName()
);
$flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)
->getMessageQueueByIdentifier('extbase.flashmessages.' . $pluginNamespace);
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$moduleTemplate->setFlashMessageQueue($renderingContext->getControllerContext()->getFlashMessageQueue());
$moduleTemplate->setFlashMessageQueue($flashMessageQueue);
$viewHelperVariableContainer->add(self::class, ModuleTemplate::class, $moduleTemplate);
$moduleTemplate->setContent($renderChildrenClosure());
......
......@@ -43,3 +43,7 @@ services:
TYPO3\CMS\Extbase\Mvc\View\GenericViewResolver: ~
TYPO3\CMS\Extbase\Mvc\View\ViewResolverInterface: '@TYPO3\CMS\Extbase\Mvc\View\GenericViewResolver'
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder:
public: true
shared: false
......@@ -85,7 +85,8 @@ class DownloadExtensionViewHelper extends AbstractFormViewHelper
}
$pathSelector .= '</ul>';
/** @var UriBuilder $uriBuilder */
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$action = 'checkDependencies';
$uriBuilder->reset();
$uriBuilder->setFormat('json');
......
......@@ -76,7 +76,8 @@ class ReloadSqlDataViewHelper extends ActionViewHelper
}
/** @var UriBuilder $uriBuilder */
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$uriBuilder->reset();
$uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
$this->tag->addAttribute('href', $uri);
......
......@@ -60,7 +60,8 @@ class RemoveExtensionViewHelper extends ActionViewHelper
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
/** @var UriBuilder $uriBuilder */
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$action = 'removeExtension';
$uriBuilder->reset();
$uriBuilder->setFormat('json');
......
......@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
......@@ -57,7 +58,8 @@ class ToggleExtensionInstallationStateViewHelper extends ActionViewHelper
return '';
}
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$action = 'toggleExtensionInstallationState';
$uri = $uriBuilder->reset()->uriFor($action, [
'extensionKey' => $extension['key']
......
......@@ -52,7 +52,8 @@ class UpdateScriptViewHelper extends ActionViewHelper
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if ($updateScriptUtility->checkUpdateScriptExists($extensionKey)) {
/** @var UriBuilder $uriBuilder */
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$action = 'show';
$uri = $uriBuilder->reset()->uriFor(
$action,
......
......@@ -42,7 +42,7 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
/**
* Controller context being passed to the ViewHelper
*
* @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext|null
* @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
*/
protected $controllerContext;
......@@ -152,9 +152,12 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
* Get the controller context which will be passed to the ViewHelper
*
* @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext The controller context to set
* @deprecated since v11, will be removed in v12
*/
public function getControllerContext()
{
// todo: trigger an error as soon as ControllerContext is deprecated
if ($this->controllerContext) {
return $this->controllerContext;
}
......
......@@ -16,6 +16,8 @@
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
......@@ -81,7 +83,10 @@ class ActionMenuItemViewHelper extends AbstractTagBasedViewHelper
$action = $this->arguments['action'];
$arguments = $this->arguments['arguments'];
$uri = $this->renderingContext->getControllerContext()->getUriBuilder()->reset()->uriFor($action, $arguments, $controller);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setRequest($this->renderingContext->getRequest());
$uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
$this->tag->addAttribute('value', $uri);
if (!$this->tag->hasAttribute('selected')) {
......
......@@ -16,7 +16,9 @@
namespace TYPO3\CMS\Fluid\ViewHelpers;
use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
......@@ -127,8 +129,20 @@ class FlashMessagesViewHelper extends AbstractViewHelper
{
$as = $arguments['as'];
$queueIdentifier = $arguments['queueIdentifier'] ?? null;
$flashMessages = $renderingContext->getControllerContext()
->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
if ($queueIdentifier === null) {
$extensionService = GeneralUtility::makeInstance(ExtensionService::class);
$pluginNamespace = $extensionService->getPluginNamespace(
$renderingContext->getRequest()->getControllerExtensionName(),
$renderingContext->getRequest()->getPluginName()
);
$queueIdentifier = 'extbase.flashmessages.' . $pluginNamespace;
}
$flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)
->getMessageQueueByIdentifier($queueIdentifier);
$flashMessages = $flashMessageQueue->getAllMessagesAndFlush();
if ($flashMessages === null || count($flashMessages) === 0) {
return '';
}
......
......@@ -17,6 +17,9 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper;
use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
......@@ -25,6 +28,8 @@ use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
*/
class FlashMessagesViewHelperTest extends ViewHelperBaseTestcase
{
protected $resetSingletonInstances = true;
/**
* @var \TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper
*/
......@@ -41,8 +46,16 @@ class FlashMessagesViewHelperTest extends ViewHelperBaseTestcase
protected function setUp(): void
{
parent::setUp();
$extensionService = $this->prophesize(ExtensionService::class);
$extensionService->getPluginNamespace(\Prophecy\Argument::cetera(), \Prophecy\Argument::cetera())->willReturn('foo');
GeneralUtility::setSingletonInstance(ExtensionService::class, $extensionService->reveal());
$this->flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
$this->controllerContext->expects(self::any())->method('getFlashMessageQueue')->willReturn($this->flashMessageQueue->reveal());
$flashMessageService = $this->prophesize(FlashMessageService::class);
$flashMessageService->getMessageQueueByIdentifier(\Prophecy\Argument::cetera())->willReturn($this->flashMessageQueue->reveal());
GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
$this->viewHelper = new FlashMessagesViewHelper();
$this->injectDependenciesIntoViewHelper($this->viewHelper);
......@@ -71,7 +84,6 @@ class FlashMessagesViewHelperTest extends ViewHelperBaseTestcase
$queueIdentifier = 'myQueue';
$this->flashMessageQueue->getAllMessagesAndFlush()->willReturn();
$this->controllerContext->expects(self::once())->method('getFlashMessageQueue')->with($queueIdentifier)->willReturn($this->flashMessageQueue->reveal());
$this->setArgumentsUnderTest(
$this->viewHelper,
......
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