Skip to content

Commit 11c84ba

Browse files
committed
[TASK] Replace "new" button for scheduler tasks in FormEngine
Editing a `tx_scheduler_task` also allowed creating a new task via the "New" button in the FormEngine doc header. However, since #107526, the task type can no longer be changed in FormEngine. Therefore, the "New" button was hidden as it led to a broken editing view. Thanks to #107471, a dedicated wizard is available for creating new tasks. This wizard can therefore now be used in FormEngine. Resolves: #107539 Related: #107471 Related: #107526 Releases: main Change-Id: I77f8887dba0dba902cd2af6ae70844fd448f00a3 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/90798 Reviewed-by: Garvin Hicking <garvin@hick.ing> Tested-by: Oli Bartsch <bo@cedev.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Tested-by: Garvin Hicking <garvin@hick.ing> Reviewed-by: Oli Bartsch <bo@cedev.de> Tested-by: Benni Mack <benni@typo3.org>
1 parent 3ed5049 commit 11c84ba

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
namespace TYPO3\CMS\Scheduler\EventListener;
19+
20+
use Psr\Http\Message\ServerRequestInterface;
21+
use TYPO3\CMS\Backend\Routing\UriBuilder;
22+
use TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent;
23+
use TYPO3\CMS\Core\Attribute\AsEventListener;
24+
use TYPO3\CMS\Core\Imaging\IconFactory;
25+
use TYPO3\CMS\Core\Imaging\IconSize;
26+
use TYPO3\CMS\Core\Localization\LanguageService;
27+
use TYPO3\CMS\Core\Page\PageRenderer;
28+
use TYPO3\CMS\Core\Utility\GeneralUtility;
29+
30+
/**
31+
* Listener replaces the "New" button of FormEngine with the button to open the scheduler task wizard
32+
*/
33+
final readonly class ReplaceAddNewButtonToFormEngine
34+
{
35+
public function __construct(
36+
private IconFactory $iconFactory,
37+
private PageRenderer $pageRenderer,
38+
private UriBuilder $uriBuilder,
39+
) {}
40+
41+
#[AsEventListener]
42+
public function __invoke(ModifyButtonBarEvent $event): void
43+
{
44+
$request = $this->getRequest();
45+
46+
if (($request->getAttribute('routing')?->getRoute()?->getOptions()['_identifier'] ?? '') !== 'record_edit') {
47+
return;
48+
}
49+
50+
$editConfig = $request->getQueryParams()['edit'] ?? null;
51+
if (!is_array($editConfig) || $editConfig === [] || count($editConfig) > 1 || key($editConfig) !== 'tx_scheduler_task') {
52+
return;
53+
}
54+
55+
$buttons = $event->getButtons();
56+
$leftButtons = $buttons['left'] ?? [];
57+
58+
$this->pageRenderer->loadJavaScriptModule('@typo3/scheduler/new-scheduler-task-wizard-button.js');
59+
60+
$addTaskUrl = (string)$this->uriBuilder->buildUriFromRoute('ajax_new_scheduler_task_wizard', [
61+
'returnUrl' => GeneralUtility::sanitizeLocalUrl($request->getQueryParams()['returnUrl'] ?? '') ?: $request->getAttribute('normalizedParams')->getRequestUri(),
62+
]);
63+
64+
$languageService = $this->getLanguageService();
65+
$newButton = $event->getButtonBar()->makeFullyRenderedButton()->setHtmlSource(
66+
'<typo3-scheduler-new-task-wizard-button url="' . $addTaskUrl . '" subject="' . htmlspecialchars($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:function.add')) . '">'
67+
. $this->iconFactory->getIcon('actions-plus', IconSize::SMALL) . htmlspecialchars($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:function.add')) .
68+
'</typo3-scheduler-new-task-wizard-button>'
69+
);
70+
71+
// Find and replace t3js-editform-new button
72+
// By replacing the existing button we ensure to respect TSconfig and that user has necessary permissions
73+
foreach ($leftButtons as $groupIndex => $buttonGroup) {
74+
foreach ($buttonGroup as $buttonIndex => $button) {
75+
if (method_exists($button, 'getClasses') && str_contains($button->getClasses(), 't3js-editform-new')) {
76+
$leftButtons[$groupIndex][$buttonIndex] = $newButton;
77+
}
78+
}
79+
}
80+
81+
$buttons['left'] = $leftButtons;
82+
$event->setButtons($buttons);
83+
}
84+
85+
private function getLanguageService(): LanguageService
86+
{
87+
return $GLOBALS['LANG'];
88+
}
89+
90+
private function getRequest(): ServerRequestInterface
91+
{
92+
return $GLOBALS['TYPO3_REQUEST'];
93+
}
94+
}

typo3/sysext/scheduler/Configuration/user.tsconfig

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)