TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard\DTO;
|
||||
|
||||
/**
|
||||
* DTO for wizard configuration holding all steps.
|
||||
* Used in WizardProviderInterface::getConfiguration() when dynamically loading wizard steps.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class Configuration implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param Step[] $steps
|
||||
*/
|
||||
private function __construct(private array $steps)
|
||||
{
|
||||
foreach ($steps as $step) {
|
||||
if (!$step instanceof Step) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
'All elements of $steps must be instances of WizardStepDTO, got %s',
|
||||
get_debug_type($step)
|
||||
),
|
||||
1772114103
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Step[]
|
||||
*/
|
||||
public function getSteps(): array
|
||||
{
|
||||
return $this->steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Step[] $steps
|
||||
* @return self
|
||||
*/
|
||||
public static function create(array $steps): self
|
||||
{
|
||||
return new self($steps);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'steps' => array_map(fn(Step $step) => $step->jsonSerialize(), $this->steps),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard\DTO;
|
||||
|
||||
/**
|
||||
* DTO for a wizard finisher, representing the action after submitting wizard data.
|
||||
* Used in WizardProviderInterface::handleSubmit() when handling wizard submit.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class Finisher implements \JsonSerializable
|
||||
{
|
||||
private function __construct(
|
||||
private string $identifier,
|
||||
private string $module,
|
||||
private string $successTitle,
|
||||
private string $successMessage,
|
||||
private array $data = []
|
||||
) {}
|
||||
|
||||
public function withResetButton(string $resetButtonLabel): self
|
||||
{
|
||||
$newData = $this->data;
|
||||
$newData['resetButtonTitle'] = $resetButtonLabel;
|
||||
|
||||
// Return a new instance with the updated data
|
||||
return new self(
|
||||
identifier: $this->identifier,
|
||||
module: $this->module,
|
||||
successTitle: $this->successTitle,
|
||||
successMessage: $this->successMessage,
|
||||
data: $newData
|
||||
);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'identifier' => $this->identifier,
|
||||
'module' => $this->module,
|
||||
'data' => $this->data,
|
||||
'labels' => [
|
||||
'successTitle' => $this->successTitle,
|
||||
'successDescription' => $this->successMessage,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function createRedirectFinisher(string $url, string $successTitle, string $successMessage): self
|
||||
{
|
||||
return new self(
|
||||
identifier: 'redirect',
|
||||
module: '@typo3/backend/wizard/finisher/redirect-finisher.js',
|
||||
successTitle: $successTitle,
|
||||
successMessage: $successMessage,
|
||||
data: [
|
||||
'url' => $url,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public static function createNoopFinisher(string $successTitle, string $successMessage): self
|
||||
{
|
||||
return new self(
|
||||
identifier: 'noop',
|
||||
module: '@typo3/backend/wizard/finisher/noop-finisher.js',
|
||||
successTitle: $successTitle,
|
||||
successMessage: $successMessage,
|
||||
);
|
||||
}
|
||||
|
||||
public static function createReloadFinisher(string $successTitle, string $successMessage): self
|
||||
{
|
||||
return new self(
|
||||
identifier: 'reload',
|
||||
module: '@typo3/backend/wizard/finisher/reload-finisher.js',
|
||||
successTitle: $successTitle,
|
||||
successMessage: $successMessage,
|
||||
);
|
||||
}
|
||||
|
||||
public static function createCustomFinisher(
|
||||
string $identifier,
|
||||
string $module,
|
||||
string $successTitle,
|
||||
string $successMessage,
|
||||
array $data = []
|
||||
): self {
|
||||
return new self($identifier, $module, $successTitle, $successMessage, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard\DTO;
|
||||
|
||||
/**
|
||||
* DTO for a single wizard step with module and configuration data.
|
||||
* Used in WizardProviderInterface::getConfiguration() when dynamically loading wizard steps.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Step implements \JsonSerializable
|
||||
{
|
||||
private array $configurationData = [];
|
||||
|
||||
private function __construct(private readonly string $module) {}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'module' => $this->module,
|
||||
'configurationData' => $this->configurationData,
|
||||
];
|
||||
}
|
||||
|
||||
public static function create(string $module): self
|
||||
{
|
||||
return new self($module);
|
||||
}
|
||||
|
||||
public function withConfigurationData(array $configurationData): self
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->configurationData = $configurationData;
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard\DTO;
|
||||
|
||||
/**
|
||||
* DTO for the result of submitting wizard data, including success state, errors, and optional finisher.
|
||||
* Used in WizardProviderInterface::handleSubmit() when returning the outcome of a wizard submission.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class SubmissionResult implements \JsonSerializable
|
||||
{
|
||||
private function __construct(
|
||||
private bool $success = true,
|
||||
private ?Finisher $finisher = null,
|
||||
private array $errors = []
|
||||
) {}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$data = [
|
||||
'success' => $this->success,
|
||||
];
|
||||
|
||||
if ($this->finisher !== null) {
|
||||
$data['finisher'] = $this->finisher->jsonSerialize();
|
||||
}
|
||||
|
||||
if (!empty($this->errors)) {
|
||||
$data['errors'] = $this->errors;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function createSuccessResult(
|
||||
Finisher $finisher
|
||||
): self {
|
||||
return new self(
|
||||
success: true,
|
||||
finisher: $finisher
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $errors
|
||||
*/
|
||||
public static function createErrorResult(array $errors): self
|
||||
{
|
||||
return new self(
|
||||
success: false,
|
||||
errors: $errors
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
|
||||
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\Configuration;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\Finisher;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\Step;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\SubmissionResult;
|
||||
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
#[AsTaggedItem(index: 'page_wizard')]
|
||||
class PageWizardProvider implements WizardProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private UriBuilder $uriBuilder,
|
||||
private PageWizardStepBuilder $stepFactory,
|
||||
) {}
|
||||
|
||||
public function getConfiguration(ServerRequestInterface $serverRequest): Configuration
|
||||
{
|
||||
if (!isset($serverRequest->getQueryParams()['data']['doktype'])) {
|
||||
return Configuration::create([
|
||||
Step::create('@typo3/backend/page-wizard/steps/form-engine-step.js')
|
||||
->withConfigurationData([
|
||||
'title' => 'Error',
|
||||
'key' => 'error',
|
||||
'html' => 'Invalid wizard submission!',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
$doktype = $serverRequest->getQueryParams()['data']['doktype'];
|
||||
$position = $serverRequest->getQueryParams()['data']['position'] ?? [];
|
||||
$pageUid = (int)($position['pageUid'] ?? 0);
|
||||
$insertPosition = $position['insertPosition'] ?? 'inside';
|
||||
$parentPageUid = $insertPosition === 'inside'
|
||||
? $pageUid
|
||||
: (int)(BackendUtility::getRecord('pages', $pageUid, 'pid')['pid'] ?? 0);
|
||||
$steps = $this->stepFactory->getStepsForDokType($doktype, $parentPageUid, $serverRequest);
|
||||
return Configuration::create($steps);
|
||||
}
|
||||
|
||||
public function handleSubmit(ServerRequestInterface $serverRequest): SubmissionResult
|
||||
{
|
||||
$params = $serverRequest->getParsedBody();
|
||||
|
||||
try {
|
||||
$pageData = $params['data']['pages'] ?? throw new \InvalidArgumentException('No data was submitted.', 1774432979);
|
||||
$newPageIdPlaceholder = key($pageData);
|
||||
$dataMap['pages'] = $pageData;
|
||||
// set doktype and pid manually as they are no native formengine fields
|
||||
$pageUid = (int)($params['position']['pageUid'] ?? throw new \InvalidArgumentException('Page position is not set', 1774433001));
|
||||
$insertPosition = $params['position']['insertPosition'] ?? 'inside';
|
||||
// DataHandler convention: a negative pid inserts the record after the record whose uid equals abs(pid).
|
||||
$dataMap['pages'][$newPageIdPlaceholder]['pid'] = $insertPosition === 'after' ? -$pageUid : $pageUid;
|
||||
$dataMap['pages'][$newPageIdPlaceholder]['doktype'] = (string)($params['doktype'] ?? throw new \InvalidArgumentException('Doktype is not set', 1774433002));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return SubmissionResult::createErrorResult([$e->getMessage()]);
|
||||
}
|
||||
|
||||
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
|
||||
$dataHandler->start($dataMap, []);
|
||||
$dataHandler->process_datamap();
|
||||
|
||||
if ($dataHandler->errorLog !== []) {
|
||||
return SubmissionResult::createErrorResult(
|
||||
$dataHandler->errorLog,
|
||||
);
|
||||
}
|
||||
$newPageUid = $dataHandler->substNEWwithIDs[$newPageIdPlaceholder] ?? null;
|
||||
|
||||
$redirectUrl = (string)$this->uriBuilder->buildUriFromRoute('web_layout', [
|
||||
'id' => $newPageUid,
|
||||
]);
|
||||
|
||||
return SubmissionResult::createSuccessResult(
|
||||
Finisher::createRedirectFinisher(
|
||||
$redirectUrl,
|
||||
$this->getLanguageService()->translate('page_wizard.success.title', 'backend.wizards.page'),
|
||||
$this->getLanguageService()->translate('page_wizard.success.description', 'backend.wizards.page'),
|
||||
)->withResetButton($this->getLanguageService()->translate('page_wizard.button.create_another_page', 'backend.wizards.page'))
|
||||
);
|
||||
}
|
||||
|
||||
private function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Backend\Form\FormDataCompiler;
|
||||
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
|
||||
use TYPO3\CMS\Backend\Form\FormResultFactory;
|
||||
use TYPO3\CMS\Backend\Form\NodeFactory;
|
||||
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\Step;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
|
||||
use TYPO3\CMS\Core\Schema\Exception\UndefinedSchemaException;
|
||||
use TYPO3\CMS\Core\Schema\Field\FieldCollection;
|
||||
use TYPO3\CMS\Core\Schema\Field\FieldTypeInterface;
|
||||
use TYPO3\CMS\Core\Schema\Struct\WizardStep;
|
||||
use TYPO3\CMS\Core\Schema\TcaSchema;
|
||||
use TYPO3\CMS\Core\Schema\TcaSchemaFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\StringUtility;
|
||||
|
||||
/**
|
||||
* @internal This is not a public API method, do not use in own extensions
|
||||
*/
|
||||
final readonly class PageWizardStepBuilder
|
||||
{
|
||||
public function __construct(
|
||||
private TcaSchemaFactory $tcaSchemaFactory,
|
||||
private UriBuilder $uriBuilder,
|
||||
private NodeFactory $nodeFactory,
|
||||
private FormResultFactory $formResultFactory,
|
||||
private FormDataCompiler $formDataCompiler,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws UndefinedSchemaException
|
||||
*/
|
||||
public function getStepsForDokType(string $dokType, int $pageUid, ServerRequestInterface $serverRequest): array
|
||||
{
|
||||
$steps = [];
|
||||
$dokTypeSchema = $this->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' => '<form name="editform">' . $formResult->html . '<input type="submit" hidden></form>',
|
||||
'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'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\Configuration;
|
||||
use TYPO3\CMS\Backend\Wizard\DTO\SubmissionResult;
|
||||
|
||||
/**
|
||||
* Interface for wizard providers.
|
||||
*
|
||||
* Use `Symfony\Component\DependencyInjection\Attribute\AsTaggedItem` attribute to define
|
||||
* the wizard identifier.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#[AutoconfigureTag('backend.wizard.provider')]
|
||||
interface WizardProviderInterface
|
||||
{
|
||||
public function getConfiguration(ServerRequestInterface $serverRequest): Configuration;
|
||||
|
||||
public function handleSubmit(ServerRequestInterface $serverRequest): SubmissionResult;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Wizard;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final readonly class WizardProviderRegistry
|
||||
{
|
||||
/**
|
||||
* @param ServiceLocator<WizardProviderInterface> $wizardProviders
|
||||
*/
|
||||
public function __construct(
|
||||
#[AutowireLocator(
|
||||
services: 'backend.wizard.provider',
|
||||
)]
|
||||
private ServiceLocator $wizardProviders,
|
||||
) {}
|
||||
|
||||
public function getProvider(string $identifier): WizardProviderInterface
|
||||
{
|
||||
if (!$this->wizardProviders->has($identifier)) {
|
||||
throw new \RuntimeException('WizardProvider "' . $identifier . '" not found', 1772114079);
|
||||
}
|
||||
return $this->wizardProviders->get($identifier);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user