Refactor creating of default form to use templates
[MAILPOET-2985]
This commit is contained in:
committed by
Veljko V
parent
4fc3d7b686
commit
14aa0b1393
@@ -21,8 +21,10 @@ class FormFactory {
|
||||
$this->formTemplateRepository = $formTemplateRepository;
|
||||
}
|
||||
|
||||
public function createFormFromTemplate(string $templateId): FormEntity {
|
||||
public function createFormFromTemplate(string $templateId, array $settings = []): FormEntity {
|
||||
$formEntity = $this->formTemplateRepository->getFormEntityForTemplate($templateId);
|
||||
$formSettings = $formEntity->getSettings() ?? [];
|
||||
$formEntity->setSettings(array_merge($formSettings, $settings));
|
||||
$this->formRepository->persist($formEntity);
|
||||
$this->formRepository->flush();
|
||||
return $formEntity;
|
||||
@@ -31,4 +33,18 @@ class FormFactory {
|
||||
public function createEmptyForm(): FormEntity {
|
||||
return $this->createFormFromTemplate(TemplateRepository::INITIAL_FORM_TEMPLATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $defaultSegmentId
|
||||
* @return FormEntity|null
|
||||
*/
|
||||
public function ensureDefaultFormExists(int $defaultSegmentId) {
|
||||
if ($this->formRepository->count()) {
|
||||
return null;
|
||||
}
|
||||
return $this->createFormFromTemplate(
|
||||
TemplateRepository::DEFAULT_FORM_TEMPLATE,
|
||||
['segments' => [(string)$defaultSegmentId]]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user