diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php new file mode 100644 index 00000000..354f2cc2 --- /dev/null +++ b/Classes/Controller/ActionController.php @@ -0,0 +1,28 @@ +request, + $this->settings, + $this->view + ); + + $this->eventDispatcher->dispatch($modifyViewEvent); + } +} diff --git a/Classes/Controller/Backend/Order/OrderController.php b/Classes/Controller/Backend/Order/OrderController.php index 7d82f3e4..4c4ad9c0 100644 --- a/Classes/Controller/Backend/Order/OrderController.php +++ b/Classes/Controller/Backend/Order/OrderController.php @@ -17,6 +17,7 @@ use Extcode\Cart\Domain\Repository\Order\ItemRepository; use Extcode\Cart\Event\Order\NumberGeneratorEvent; use Extcode\Cart\Event\Template\Components\ModifyButtonBarEvent; +use Extcode\Cart\Event\Template\Components\ModifyModuleTemplateEvent; use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Template\ModuleTemplate; @@ -92,6 +93,8 @@ public function listAction(int $currentPage = 1): ResponseInterface $pdfRendererInstalled = ExtensionManagementUtility::isLoaded('cart_pdf'); $this->moduleTemplate->assign('pdfRendererInstalled', $pdfRendererInstalled); + $this->dispatchModifyModuleTemplateEvent(); + return $this->moduleTemplate->renderResponse('List'); } @@ -129,6 +132,8 @@ public function showAction(Item $orderItem): ResponseInterface $pdfRendererInstalled = ExtensionManagementUtility::isLoaded('cart_pdf'); $this->moduleTemplate->assign('pdfRendererInstalled', $pdfRendererInstalled); + $this->dispatchModifyModuleTemplateEvent(); + return $this->moduleTemplate->renderResponse('Show'); } @@ -241,16 +246,27 @@ protected function getLanguageService(): LanguageService private function dispatchModifyButtonBarEvent(?Item $orderItem = null): array { - $modifyButtonBarEvent = new ModifyButtonBarEvent( + $event = new ModifyButtonBarEvent( $this->request, $this->settings, $this->searchArguments, $orderItem ); - $this->eventDispatcher->dispatch($modifyButtonBarEvent); + $this->eventDispatcher->dispatch($event); + + return $event->getButtons(); + } + + private function dispatchModifyModuleTemplateEvent(): void + { + $event = new ModifyModuleTemplateEvent( + $this->request, + $this->settings, + $this->moduleTemplate + ); - return $modifyButtonBarEvent->getButtons(); + $this->eventDispatcher->dispatch($event); } private function setDocHeader(array $buttons): void diff --git a/Classes/Controller/Cart/ActionController.php b/Classes/Controller/Cart/ActionController.php index a3ab9bb9..fdf54a7a 100644 --- a/Classes/Controller/Cart/ActionController.php +++ b/Classes/Controller/Cart/ActionController.php @@ -19,7 +19,7 @@ use Extcode\Cart\Utility\CartUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; -abstract class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController +abstract class ActionController extends \Extcode\Cart\Controller\ActionController { protected SessionHandler $sessionHandler; diff --git a/Classes/Controller/Cart/CartController.php b/Classes/Controller/Cart/CartController.php index 7224e066..bb20df28 100755 --- a/Classes/Controller/Cart/CartController.php +++ b/Classes/Controller/Cart/CartController.php @@ -145,8 +145,10 @@ public function showAction( if (count($this->cart->getProducts()) === 0 && $currentStep > 1) { return $this->redirect('show', null, null, ['step' => 1])->withStatus(303); } - return $this->htmlResponse(); + $this->dispatchModifyViewEvent(); + + return $this->htmlResponse(); } public function clearAction(): ResponseInterface diff --git a/Classes/Controller/Cart/CartPreviewController.php b/Classes/Controller/Cart/CartPreviewController.php index 30999a6e..eefb8f4b 100755 --- a/Classes/Controller/Cart/CartPreviewController.php +++ b/Classes/Controller/Cart/CartPreviewController.php @@ -25,6 +25,8 @@ public function showAction(): ResponseInterface $this->view->assign('cart', $this->cart); + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } } diff --git a/Classes/Controller/Cart/CountryController.php b/Classes/Controller/Cart/CountryController.php index 3e54da33..6c03cb26 100644 --- a/Classes/Controller/Cart/CountryController.php +++ b/Classes/Controller/Cart/CountryController.php @@ -63,6 +63,8 @@ public function updateAction(): ResponseInterface $this->view->assign('cart', $this->cart); + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } } diff --git a/Classes/Controller/Cart/CurrencyController.php b/Classes/Controller/Cart/CurrencyController.php index 753c92b5..a0868958 100644 --- a/Classes/Controller/Cart/CurrencyController.php +++ b/Classes/Controller/Cart/CurrencyController.php @@ -41,6 +41,8 @@ public function updateAction(): ResponseInterface $this->parseServicesAndAssignToView(); } + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } } diff --git a/Classes/Controller/Cart/OrderController.php b/Classes/Controller/Cart/OrderController.php index 228d7d63..77a3effc 100644 --- a/Classes/Controller/Cart/OrderController.php +++ b/Classes/Controller/Cart/OrderController.php @@ -113,6 +113,7 @@ public function createAction( $isPropagationStopped = $this->dispatchOrderCreateEvents($orderItem); if ($isPropagationStopped) { + $this->dispatchModifyViewEvent(); // @todo Check the Response Type return $this->htmlResponse(); } @@ -127,6 +128,8 @@ public function createAction( $this->redirectToUri($paymentSettings['options'][$paymentId]['redirects']['success']['url'], 0, 200); } + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } @@ -134,6 +137,8 @@ public function showAction(Item $orderItem): ResponseInterface { $this->view->assign('orderItem', $orderItem); + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } diff --git a/Classes/Controller/Cart/PaymentController.php b/Classes/Controller/Cart/PaymentController.php index 36b27f73..114ddae4 100644 --- a/Classes/Controller/Cart/PaymentController.php +++ b/Classes/Controller/Cart/PaymentController.php @@ -50,6 +50,9 @@ public function updateAction(int $paymentId): ResponseInterface $this->view->assign('cart', $this->cart); $this->parseServicesAndAssignToView(); + + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } diff --git a/Classes/Controller/Cart/ShippingController.php b/Classes/Controller/Cart/ShippingController.php index 4ca8813a..444c62a1 100644 --- a/Classes/Controller/Cart/ShippingController.php +++ b/Classes/Controller/Cart/ShippingController.php @@ -50,6 +50,9 @@ public function updateAction(int $shippingId): ResponseInterface $this->view->assign('cart', $this->cart); $this->parseServicesAndAssignToView(); + + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } diff --git a/Classes/Controller/Order/OrderController.php b/Classes/Controller/Order/OrderController.php index da338656..71715170 100644 --- a/Classes/Controller/Order/OrderController.php +++ b/Classes/Controller/Order/OrderController.php @@ -10,6 +10,8 @@ * For the full copyright and license information, please read the * LICENSE file that was distributed with this source code. */ + +use Extcode\Cart\Controller\ActionController; use Extcode\Cart\Domain\Model\Order\Item; use Extcode\Cart\Domain\Repository\Order\ItemRepository; use Psr\Http\Message\ResponseInterface; @@ -19,7 +21,6 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Extbase\Annotation\IgnoreValidation; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; -use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -65,6 +66,8 @@ public function listAction(int $currentPage = 1): ResponseInterface ] ); + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } @@ -106,6 +109,8 @@ public function showAction(Item $orderItem): ResponseInterface $pdfRendererInstalled = ExtensionManagementUtility::isLoaded('cart_pdf'); $this->view->assign('pdfRendererInstalled', $pdfRendererInstalled); + $this->dispatchModifyViewEvent(); + return $this->htmlResponse(); } } diff --git a/Classes/Event/Template/Components/ModifyModuleTemplateEvent.php b/Classes/Event/Template/Components/ModifyModuleTemplateEvent.php new file mode 100644 index 00000000..e88fe160 --- /dev/null +++ b/Classes/Event/Template/Components/ModifyModuleTemplateEvent.php @@ -0,0 +1,39 @@ +request; + } + + public function getSettings(): array + { + return $this->settings; + } + + public function getModuleTemplate(): ModuleTemplate + { + return $this->moduleTemplate; + } +} diff --git a/Classes/Event/View/ModifyViewEvent.php b/Classes/Event/View/ModifyViewEvent.php new file mode 100644 index 00000000..1d2a00f1 --- /dev/null +++ b/Classes/Event/View/ModifyViewEvent.php @@ -0,0 +1,39 @@ +request; + } + + public function getSettings(): array + { + return $this->settings; + } + + public function getView(): ViewInterface + { + return $this->view; + } +} diff --git a/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToModuleTemplate.rst b/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToModuleTemplate.rst new file mode 100644 index 00000000..130a1e73 --- /dev/null +++ b/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToModuleTemplate.rst @@ -0,0 +1,30 @@ +.. include:: ../../Includes.rst.txt + +============================================================== +Feature: #593 - Add event to assign own data to moduleTemplate +============================================================== + +See `Issue 593 `__ + +Description +=========== + +Adding your own data to module templates is not so easy. In order to assign +own data to the moduleTemplate, you need a way to assign your own data if you +do not want to develop your own backend module. + +The `\Extcode\Cart\Event\Template\Components\ModifyModuleTemplateEvent` event +is dispached in the OrderController for the backend module. + +An own EventListener can use the methods `getRequest()`, `getSettings()`, +`getModuleTemplate()` to retrieve all the necessary information to assign custom +data. +The request object can be used to assign data for specific actions. + +Impact +====== + +No impact is expected. + + +.. index:: Backend diff --git a/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToView.rst b/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToView.rst new file mode 100644 index 00000000..d6f7d39a --- /dev/null +++ b/Documentation/Changelog/9.1/Feature-593-AddEventToAssignOwnDataToView.rst @@ -0,0 +1,32 @@ +.. include:: ../../Includes.rst.txt + +==================================================== +Feature: #593 - Add event to assign own data to view +==================================================== + +See `Issue 593 `__ + +Description +=========== + +Adding your own data to plugin templates is not so easy. In order to assign +own data to the view, you need a lib in TypoScript and a f:cObject in the +template with some JavaScript on top. + +This `\Extcode\Cart\Event\View\ModifyViewEvent` event is dispached in all +actions for which an output is generated via a template. Actions that are +forwarded to another action do not require the event. + +An own EventListener can use the methods `getRequest()`, `getSettings()`, +`getView()` to retrieve all the necessary information to assign custom data. +The request object can be used to assign data for specific actions. For example, +saved addresses of a returning logged-in user can be displayed for selection +instead of the form for the billing address. + +Impact +====== + +No impact is expected. + + +.. index:: Backend diff --git a/Documentation/Developer/Events/Index.rst b/Documentation/Developer/Events/Index.rst index 9852ddc2..fea2e518 100644 --- a/Documentation/Developer/Events/Index.rst +++ b/Documentation/Developer/Events/Index.rst @@ -10,14 +10,6 @@ integrate custom requirements in the ordering process. You can register your own EventListener for the following events: -.. confval:: \Extcode\Cart\Event\Template\Components\ModifyButtonBarEvent - - This event is triggered in the `listAction` and `showAction` of the backend - module `OrderController`. - - The event allows to add own buttons or change existing buttons in the - DocHeader of the module template. - .. confval:: \Extcode\Cart\Event\Cart\BeforeShowCartEvent Triggered before the cart is shown. @@ -175,3 +167,26 @@ events: This event is triggered in the `SessionHandler` and can be used to validate or change the cart before writing the data to the session. + + + +.. confval:: \Extcode\Cart\Event\Template\Components\ModifyButtonBarEvent + + This event is triggered in the `listAction` and `showAction` of the backend + module `OrderController`. + + The event allows to add own buttons or change existing buttons in the + DocHeader of the module template. + +.. confval:: \Extcode\Cart\Event\Template\Components\ModifyModuleTemplateEvent + + This event is triggered in the `listAction` and `showAction` of the backend + module `OrderController`. + + The event allows to assign own data to the module template. + +.. confval:: \Extcode\Cart\Event\View\ModifyViewEvent + + This event is triggered in the several actions of the frontend plugins. + + The event allows to assign own data to the view. diff --git a/Documentation/guides.xml b/Documentation/guides.xml index ebe13431..ad995743 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart" /> diff --git a/ext_emconf.php b/ext_emconf.php index 6868636a..d2850cac 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Cart', 'description' => 'Shopping Cart(s) for TYPO3', 'category' => 'plugin', - 'version' => '9.0.3', + 'version' => '9.1.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',