returnUrl = GeneralUtility::sanitizeLocalUrl((string)($request->getParsedBody()['returnUrl'] ?? $request->getQueryParams()['returnUrl'] ?? ''), $request); $this->defaultValues = $request->getParsedBody()['defaultValues'] ?? $request->getQueryParams()['defaultValues'] ?? []; $wizardItems = $this->eventDispatcher->dispatch( new ModifyNewSchedulerTaskWizardItemsEvent( $this->getWizardItemsFromTaskRegistry(), $request, ) )->getWizardItems(); $view = $this->backendViewFactory->create($request); $view->assign('categoriesJson', GeneralUtility::jsonEncodeForHtmlAttribute($this->organizeWizardItems($wizardItems), false)); return new HtmlResponse($view->render('NewSchedulerTask/Wizard')); } /** * Convert TaskService categorized tasks to wizard items */ protected function getWizardItemsFromTaskRegistry(): array { $wizardItems = []; foreach ($this->taskService->getCategorizedTaskTypes() as $category => $tasks) { // Add category header $wizardItems[$category] = [ 'header' => ucfirst($category), ]; // Add tasks for this category foreach ($tasks as $taskType => $taskInfo) { $wizardItems[$category . '_' . str_replace('\\', '_', $taskType)] = [ 'title' => $taskInfo['title'], 'description' => $taskInfo['description'], // @todo change once tx_scheduler_task get's icons 'icon' => $taskInfo['icon'] ?? 'mimetypes-x-tx_scheduler_task_group', 'iconOverlay' => $taskInfo['iconOverlay'] ?? '', 'taskType' => $taskType, 'taskClass' => $taskInfo['className'], ]; } } return $wizardItems; } /** * Organize wizard items into the categories */ protected function organizeWizardItems(array $wizardItems): array { $categories = []; $currentKey = ''; foreach ($wizardItems as $wizardKey => $wizardItem) { if (isset($wizardItem['header'])) { // This is a category $currentKey = $wizardKey; $categories[$currentKey] = [ 'identifier' => $currentKey, 'label' => $wizardItem['header'], 'items' => [], ]; } else { if (!($wizardItem['taskType'] ?? false)) { continue; } // This is a task item $item = [ 'identifier' => $wizardKey, 'icon' => $wizardItem['icon'] ?? 'mimetypes-x-tx_scheduler_task_group', 'iconOverlay' => $wizardItem['iconOverlay'] ?? '', 'label' => $wizardItem['title'] ?? '', 'description' => $wizardItem['description'] ?? '', 'taskType' => $wizardItem['taskType'], ]; $item['url'] = (string)$this->uriBuilder->buildUriFromRoute('record_edit', [ 'edit' => [ 'tx_scheduler_task' => [ 0 => 'new', ], ], 'defVals' => [ 'tx_scheduler_task' => array_replace_recursive($this->defaultValues, [ 'pid' => 0, 'tasktype' => $wizardItem['taskType'], ]), ], 'returnUrl' => $this->returnUrl, ]); if (!empty($currentKey)) { $categories[$currentKey]['items'][] = $item; } } } // Remove empty categories return array_filter($categories, static fn(array $category): bool => !empty($category['items'])); } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }