Skip to content

Commit

Permalink
[TASK] Use new templating strategy in ext:form
Browse files Browse the repository at this point in the history
We need to move the main templates around a bit
to apply new backend templating strategy to the
ext:form backend controllers.

Resolves: #96774
Related: #96730
Releases: main
Change-Id: I0c3f82f33c17f482a0487e3f29eb8b2ba76ff128
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73338
Tested-by: core-ci <typo3@b13.com>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
lolli42 authored and bmack committed Feb 7, 2022
1 parent ef97d5e commit c338bd7
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 359 deletions.
23 changes: 2 additions & 21 deletions typo3/sysext/form/Classes/Controller/AbstractBackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,14 @@
*/
abstract class AbstractBackendController extends ActionController
{
protected array $formSettings;
protected FormPersistenceManagerInterface $formPersistenceManager;

/**
* @var array
*/
protected $formSettings;

/**
* @var \TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
*/
protected $formPersistenceManager;

/**
* @param \TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface $formPersistenceManager
* @internal
*/
public function injectFormPersistenceManager(FormPersistenceManagerInterface $formPersistenceManager)
{
$this->formPersistenceManager = $formPersistenceManager;
}

/**
* @internal
*/
public function initializeObject()
{
$this->formSettings = GeneralUtility::makeInstance(ConfigurationManagerInterface::class)
Expand All @@ -73,9 +58,6 @@ public function initializeObject()
* [
* 0 => 'typo3/sysext/form/Resources/Public/Css/form.css'
* ]
*
* @param array $resourcePaths
* @return array
*/
protected function resolveResourcePaths(array $resourcePaths): array
{
Expand All @@ -87,7 +69,6 @@ protected function resolveResourcePaths(array $resourcePaths): array
}
$return[] = $resourcePath;
}

return $return;
}
}
79 changes: 12 additions & 67 deletions typo3/sysext/form/Classes/Controller/FormEditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,20 @@ class FormEditorController extends AbstractBackendController
{
protected const JS_MODULE_NAMES = ['app', 'mediator', 'viewModel'];

protected ModuleTemplateFactory $moduleTemplateFactory;
protected PageRenderer $pageRenderer;
protected IconFactory $iconFactory;
protected FormDefinitionConversionService $formDefinitionConversionService;

/**
* @var array
*/
protected $prototypeConfiguration;
protected array $prototypeConfiguration;

public function __construct(
ModuleTemplateFactory $moduleTemplateFactory,
PageRenderer $pageRenderer,
IconFactory $iconFactory,
FormDefinitionConversionService $formDefinitionConversionService
protected readonly ModuleTemplateFactory $moduleTemplateFactory,
protected readonly PageRenderer $pageRenderer,
protected readonly IconFactory $iconFactory,
protected readonly FormDefinitionConversionService $formDefinitionConversionService,
) {
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->pageRenderer = $pageRenderer;
$this->iconFactory = $iconFactory;
$this->formDefinitionConversionService = $formDefinitionConversionService;
}

/**
* Displays the form editor
* Display the form editor.
*
* @param string $formPersistenceIdentifier
* @param string|null $prototypeName
* @return ResponseInterface
* @throws PersistenceManagerException
* @internal
*/
public function indexAction(string $formPersistenceIdentifier, string $prototypeName = null): ResponseInterface
{
Expand Down Expand Up @@ -145,7 +129,8 @@ public function indexAction(string $formPersistenceIdentifier, string $prototype
'maximumUndoSteps' => $this->prototypeConfiguration['formEditor']['maximumUndoSteps'],
];

$this->view->assign('formEditorTemplates', $this->renderFormEditorTemplates($formEditorDefinitions));
$moduleTemplate = $this->initializeModuleTemplate($this->request);
$moduleTemplate->assign('formEditorTemplates', $this->renderFormEditorTemplates($formEditorDefinitions));

$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$addInlineSettings = [
Expand Down Expand Up @@ -196,35 +181,26 @@ public function indexAction(string $formPersistenceIdentifier, string $prototype
$pageRenderer->addCssFile($stylesheet);
}

$moduleTemplate = $this->initializeModuleTemplate($this->request);
$moduleTemplate->setModuleClass($this->request->getPluginName() . '_' . $this->request->getControllerName());
$moduleTemplate->setFlashMessageQueue($this->getFlashMessageQueue());
$moduleTemplate->setTitle(
$this->getLanguageService()->sL('LLL:EXT:form/Resources/Private/Language/locallang_module.xlf:mlang_tabs_tab'),
$formDefinition['label']
);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
return $moduleTemplate->renderResponse('Backend/FormEditor/Index');
}

/**
* Initialize the save action.
* This action uses the Fluid JsonView::class as view.
*
* @internal
*/
public function initializeSaveFormAction()
public function initializeSaveFormAction(): void
{
$this->defaultViewObjectName = JsonView::class;
}

/**
* Save a formDefinition which was build by the form editor.
*
* @param string $formPersistenceIdentifier
* @param FormDefinitionArray $formDefinition
* @return ResponseInterface
* @internal
*/
public function saveFormAction(string $formPersistenceIdentifier, FormDefinitionArray $formDefinition): ResponseInterface
{
Expand Down Expand Up @@ -274,12 +250,6 @@ public function saveFormAction(string $formPersistenceIdentifier, FormDefinition
/**
* Render a page from the formDefinition which was build by the form editor.
* Use the frontend rendering and set the form framework to preview mode.
*
* @param FormDefinitionArray $formDefinition
* @param int $pageIndex
* @param string $prototypeName
* @return ResponseInterface
* @internal
*/
public function renderFormPageAction(
FormDefinitionArray $formDefinition,
Expand All @@ -302,10 +272,6 @@ public function renderFormPageAction(
/**
* Build a SiteLanguage object to render the form preview with a
* specific language.
*
* @param int $pageId
* @param int $languageId
* @return SiteLanguage
*/
protected function buildFakeSiteLanguage(int $pageId, int $languageId): SiteLanguage
{
Expand All @@ -325,7 +291,7 @@ protected function buildFakeSiteLanguage(int $pageId, int $languageId): SiteLang
],
];

/** @var \TYPO3\CMS\Core\Site\Entity\SiteLanguage $currentSiteLanguage */
/** @var SiteLanguage $currentSiteLanguage */
$currentSiteLanguage = GeneralUtility::makeInstance(Site::class, 'form-dummy', $pageId, $fakeSiteConfiguration)
->getLanguageById($languageId);
return $currentSiteLanguage;
Expand All @@ -334,9 +300,6 @@ protected function buildFakeSiteLanguage(int $pageId, int $languageId): SiteLang
/**
* Prepare the formElements.*.formEditor section from the YAML settings.
* Sort all formElements into groups and add additional data.
*
* @param array $formElementsDefinition
* @return array
*/
protected function getInsertRenderablesPanelConfiguration(array $formElementsDefinition): array
{
Expand Down Expand Up @@ -393,8 +356,6 @@ protected function getInsertRenderablesPanelConfiguration(array $formElementsDef

/**
* Reduce the YAML settings by the 'formEditor' keyword.
*
* @return array
*/
protected function getFormEditorDefinitions(): array
{
Expand Down Expand Up @@ -428,7 +389,7 @@ protected function getFormEditorDefinitions(): array
*/
protected function initializeModuleTemplate(ServerRequestInterface $request): ModuleTemplate
{
$moduleTemplate = $this->moduleTemplateFactory->create($request);
$moduleTemplate = $this->moduleTemplateFactory->create($request, 'typo3/cms-form');

$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$getVars = $request->getArguments();
Expand Down Expand Up @@ -498,9 +459,6 @@ protected function initializeModuleTemplate(ServerRequestInterface $request): Mo

/**
* Render the "text/x-formeditor-template" templates.
*
* @param array $formEditorDefinitions
* @return string
*/
protected function renderFormEditorTemplates(array $formEditorDefinitions): string
{
Expand Down Expand Up @@ -548,8 +506,6 @@ protected function renderFormEditorTemplates(array $formEditorDefinitions): stri

/**
* @todo move this to FormDefinitionConversionService
* @param array $formDefinition
* @return array
*/
protected function transformFormDefinitionForFormEditor(array $formDefinition): array
{
Expand Down Expand Up @@ -630,11 +586,6 @@ protected function transformFormDefinitionForFormEditor(array $formDefinition):
* _value => 3
* ],
* ]
*
* @param array $formDefinition
* @param string $identifierProperty
* @param array $multiValueProperties
* @return array
*/
protected function transformMultiValuePropertiesForFormEditor(
array $formDefinition,
Expand Down Expand Up @@ -688,9 +639,6 @@ protected function transformMultiValuePropertiesForFormEditor(

/**
* Remove keys from an array if the key value is an empty array
*
* @param array $array
* @return array
*/
protected function filterEmptyArrays(array $array): array
{
Expand All @@ -713,9 +661,6 @@ protected function filterEmptyArrays(array $array): array

/**
* Migrate single recipient options to their list successors
*
* @param array $formDefinition
* @return array
*/
protected function migrateEmailFinisherRecipients(array $formDefinition): array
{
Expand Down
Loading

0 comments on commit c338bd7

Please sign in to comment.