Commit d24489a7 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Daniel Goerz
Browse files

[TASK] Deprecate ControllerContext::getFlashMessageQueue()

With this patch method getFlashMessageQueue() of ControllerContext
is deprecated and the core avoids using it.

A trigger_error call will be implemented in another patch set
which deprecates the whole ControllerContext object.

Releases: master
Resolves: #93016
Change-Id: I20b47dc26892b4affb1aec8e147169738139241c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67044


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 028eab64
......@@ -128,7 +128,7 @@ class PermissionController extends ActionController
$this->registerDocHeaderButtons();
$this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageInfo);
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
}
}
......
......@@ -23,6 +23,8 @@ use TYPO3\CMS\Core\Http\ResponseFactoryInterface;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
......@@ -48,6 +50,7 @@ use TYPO3\CMS\Extbase\Property\PropertyMapper;
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
use TYPO3\CMS\Extbase\Service\CacheService;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator;
use TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface;
......@@ -190,6 +193,16 @@ abstract class ActionController implements ControllerInterface
*/
private $propertyMapper;
/**
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
private FlashMessageService $internalFlashMessageService;
/**
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
private ExtensionService $internalExtensionService;
final public function injectResponseFactory(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
......@@ -293,6 +306,22 @@ abstract class ActionController implements ControllerInterface
$this->propertyMapper = $propertyMapper;
}
/**
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
final public function injectInternalFlashMessageService(FlashMessageService $flashMessageService): void
{
$this->internalFlashMessageService = $flashMessageService;
}
/**
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
final public function injectInternalExtensionService(ExtensionService $extensionService): void
{
$this->internalExtensionService = $extensionService;
}
/**
* Initializes the view before invoking an action method.
*
......@@ -866,7 +895,28 @@ abstract class ActionController implements ControllerInterface
$severity,
$storeInSession
);
$this->controllerContext->getFlashMessageQueue()->enqueue($flashMessage);
$this->getFlashMessageQueue()->enqueue($flashMessage);
}
/**
* todo: As soon as the incoming request contains the compiled plugin namespace, extbase will offer a trait to
* create a flash message identifier from the current request. Users then should inject the flash message
* service themselves if needed.
*
* @internal only to be used within Extbase, not part of TYPO3 Core API.
*/
protected function getFlashMessageQueue(string $identifier = null): FlashMessageQueue
{
if ($identifier === null) {
$pluginNamespace = $this->internalExtensionService->getPluginNamespace(
$this->request->getControllerExtensionName(),
$this->request->getPluginName()
);
$identifier = 'extbase.flashmessages.' . $pluginNamespace;
}
return $this->internalFlashMessageService->getMessageQueueByIdentifier($identifier);
}
/**
......
......@@ -141,9 +141,12 @@ class ControllerContext
/**
* @param string $identifier Queue-identifier
* @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
* @deprecated since v11, will be removed in v12
*/
public function getFlashMessageQueue($identifier = null)
{
// todo: trigger an error as soon as this whole object can be deprecated
if ($identifier === null) {
if ($this->flashMessageQueueDefaultIdentifier === null) {
// cache the default-identifier for performance-reasons
......
......@@ -20,13 +20,13 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
use Prophecy\Argument;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException;
use TYPO3\CMS\Extbase\Mvc\Request;
......@@ -35,6 +35,7 @@ use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Reflection\ClassSchema;
use TYPO3\CMS\Extbase\Reflection\ClassSchema\Method;
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
use TYPO3Fluid\Fluid\View\AbstractTemplateView;
use TYPO3Fluid\Fluid\View\TemplateView as FluidTemplateView;
......@@ -657,11 +658,6 @@ class ActionControllerTest extends UnitTestCase
$flashMessageQueue->expects(self::once())->method('enqueue')->with(self::equalTo($expectedMessage));
$controllerContext = $this->getMockBuilder(ControllerContext::class)
->setMethods(['getFlashMessageQueue'])
->getMock();
$controllerContext->expects(self::once())->method('getFlashMessageQueue')->willReturn($flashMessageQueue);
$controller = $this->getAccessibleMockForAbstractClass(
ActionController::class,
[],
......@@ -671,7 +667,16 @@ class ActionControllerTest extends UnitTestCase
true,
['dummy']
);
$controller->_set('controllerContext', $controllerContext);
$flashMessageService = $this->prophesize(FlashMessageService::class);
$flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue);
$controller->injectInternalFlashMessageService($flashMessageService->reveal());
$extensionService = $this->prophesize(ExtensionService::class);
$extensionService->getPluginNamespace(Argument::cetera(), Argument::cetera())->willReturn('');
$controller->injectInternalExtensionService($extensionService->reveal());
$controller->_set('request', new Request());
$controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
}
......
......@@ -110,7 +110,7 @@ class AbstractModuleController extends AbstractController
}
$this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
}
/**
......
......@@ -513,7 +513,7 @@ class FileListController extends ActionController implements LoggerAwareInterfac
{
if ($this->errorMessage) {
$this->errorMessage->setSeverity(FlashMessage::ERROR);
$this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage($this->errorMessage);
$this->getFlashMessageQueue('core.template.flashMessages')->addMessage($this->errorMessage);
}
return $this->htmlResponse($this->view->render());
......@@ -534,7 +534,7 @@ class FileListController extends ActionController implements LoggerAwareInterfac
$fileFacades = [];
if (count($files) === 0) {
$this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->addMessage(
$this->getFlashMessageQueue('core.template.flashMessages')->addMessage(
new FlashMessage(
LocalizationUtility::translate('flashmessage.no_results', 'filelist') ?? '',
'',
......
......@@ -73,7 +73,7 @@ class FormEditorController extends AbstractBackendController
{
$this->registerDocheaderButtons();
$this->view->getModuleTemplate()->setModuleName($this->request->getPluginName() . '_' . $this->request->getControllerName());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
if (
strpos($formPersistenceIdentifier, 'EXT:') === 0
......
......@@ -76,7 +76,7 @@ class FormManagerController extends AbstractBackendController
{
$this->registerDocheaderButtons();
$this->view->getModuleTemplate()->setModuleName($this->request->getPluginName() . '_' . $this->request->getControllerName());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
$this->view->assign('forms', $this->getAvailableFormDefinitions());
$this->view->assign('stylesheets', $this->resolveResourcePaths($this->formSettings['formManager']['stylesheets']));
......
......@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Form\Domain\Finishers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime;
/**
......@@ -64,15 +65,19 @@ class FinisherContext
*/
protected $finisherVariableProvider;
private Request $request;
/**
* @param FormRuntime $formRuntime
* @param ControllerContext $controllerContext
* @param Request $request
* @internal
*/
public function __construct(FormRuntime $formRuntime, ControllerContext $controllerContext)
public function __construct(FormRuntime $formRuntime, ControllerContext $controllerContext, Request $request)
{
$this->formRuntime = $formRuntime;
$this->controllerContext = $controllerContext;
$this->request = $request;
}
/**
......@@ -124,6 +129,7 @@ class FinisherContext
/**
* @return ControllerContext
* @deprecated since v11, will be removed in v12
*/
public function getControllerContext(): ControllerContext
{
......@@ -137,4 +143,9 @@ class FinisherContext
{
return $this->finisherVariableProvider;
}
public function getRequest(): Request
{
return $this->request;
}
}
......@@ -23,10 +23,12 @@ namespace TYPO3\CMS\Form\Domain\Finishers;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Extbase\Error\Error;
use TYPO3\CMS\Extbase\Error\Message;
use TYPO3\CMS\Extbase\Error\Notice;
use TYPO3\CMS\Extbase\Error\Warning;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
/**
......@@ -62,6 +64,19 @@ class FlashMessageFinisher extends AbstractFinisher
'severity' => AbstractMessage::OK,
];
private ExtensionService $extensionService;
private FlashMessageService $flashMessageService;
public function injectFlashMessageService(FlashMessageService $flashMessageService): void
{
$this->flashMessageService = $flashMessageService;
}
public function injectExtensionService(ExtensionService $extensionService): void
{
$this->extensionService = $extensionService;
}
/**
* Executes this finisher
* @see AbstractFinisher::execute()
......@@ -101,6 +116,12 @@ class FlashMessageFinisher extends AbstractFinisher
true
);
$this->finisherContext->getControllerContext()->getFlashMessageQueue()->addMessage($flashMessage);
// todo: this value has to be taken from the request directly in the future
$pluginNamespace = $this->extensionService->getPluginNamespace(
$this->finisherContext->getRequest()->getControllerExtensionName(),
$this->finisherContext->getRequest()->getPluginName()
);
$this->flashMessageService->getMessageQueueByIdentifier('extbase.flashmessages.' . $pluginNamespace)->addMessage($flashMessage);
}
}
......@@ -644,7 +644,8 @@ class FormRuntime implements RootRenderableInterface, \ArrayAccess
$finisherContext = $this->objectManager->get(
FinisherContext::class,
$this,
$this->getControllerContext()
$this->getControllerContext(),
$this->request
);
$output = '';
......
......@@ -101,7 +101,7 @@ class AdministrationController extends ActionController
$view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
}
$this->generateMenu();
$this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
$this->view->getModuleTemplate()->setFlashMessageQueue($this->getFlashMessageQueue());
$view->assign('extensionConfiguration', $this->indexerConfig);
}
}
......
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