getSchemaForDokType($dokType); $requiredFields = $dokTypeSchema->getFields(fn(FieldTypeInterface $field) => $field->isRequired())->getNames(); $newId = StringUtility::getUniqueId('NEW'); foreach ($dokTypeSchema->getWizardSteps() as $wizardStep) { $requiredFields = array_diff($requiredFields, $wizardStep->getFields()->getNames()); $formData = $this->getFormData($serverRequest, $dokType, $pageUid, $wizardStep, $newId); $steps[] = $this->buildStep($wizardStep, $formData); } if ($requiredFields !== []) { $requiredStep = new WizardStep('requiredFields', $this->getLanguageService()->sL('core.wizard:wizard.step.required'), $this->getFieldCollection($requiredFields, $dokTypeSchema)); $formData = $this->getFormData($serverRequest, $dokType, $pageUid, $requiredStep, $newId); $visibleRequiredFields = array_intersect($requiredFields, array_keys($formData['processedTca']['columns'] ?? [])); if ($visibleRequiredFields !== []) { $steps[] = $this->buildStep($requiredStep, $formData); } } return $steps; } private function buildStep(WizardStep $wizardStep, array $formData): Step { $formResult = $this->nodeFactory->create($formData)->render(); $formResult = $this->formResultFactory->create($formResult); return Step::create('@typo3/backend/page-wizard/steps/form-engine-step.js') ->withConfigurationData([ 'title' => $this->getLanguageService()->sL($wizardStep->getTitle()), 'key' => $wizardStep->getIdentifier(), 'html' => '
' . $formResult->html . '
', 'modules' => [ JavaScriptModuleInstruction::create('@typo3/backend/form-engine.js') ->invoke( 'initialize', (string)$this->uriBuilder->buildUriFromRoute('wizard_element_browser') ), ...$formResult->javaScriptModules, ], 'labels' => $this->getLabelsForFields($formData), ]); } private function getFormData(ServerRequestInterface $serverRequest, string $doktype, int $pid, WizardStep $wizardStep, string $newId): array { $fieldList = implode(',', $wizardStep->getFields()->getNames()); $formDataCompilerInput = [ 'request' => $serverRequest, 'tableName' => 'pages', 'recordTypeValue' => $doktype, 'command' => 'new', 'vanillaUid' => $pid, 'processedTca' => $GLOBALS['TCA']['pages'], 'databaseRow' => [ 'uid' => $newId, ], ]; $formDataCompilerInput['processedTca']['types'][$doktype]['showitem'] = $fieldList; $formData = $this->formDataCompiler->compile($formDataCompilerInput, GeneralUtility::makeInstance(TcaDatabaseRecord::class)); $formData['renderType'] = 'listOfFieldsContainer'; $formData['fieldListToRender'] = $fieldList; return $formData; } private function getFieldCollection(array $fieldNames, TcaSchema $tcaSchema): FieldCollection { $fields = []; foreach ($fieldNames as $fieldName) { $fields[$fieldName] = $tcaSchema->getField($fieldName); } return new FieldCollection($fields); } private function getLabelsForFields(array $formData): array { $labels = []; $processedFields = $formData['processedTca']['columns'] ?? []; foreach ($processedFields as $fieldName => $fieldConfiguration) { $labels[$fieldName] = $fieldConfiguration['label'] ?? ''; } return $labels; } /** * @throws UndefinedSchemaException * @throws \RuntimeException */ private function getSchemaForDokType(string $dokType): TcaSchema { $tcaSchema = $this->tcaSchemaFactory->get('pages'); if (!$tcaSchema->hasSubSchema($dokType)) { throw new \RuntimeException('Requested doktype is missing.', 1773673880); } return $tcaSchema->getSubSchema($dokType); } private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }