Use API to save the template

[MAILPOET-2987]
This commit is contained in:
Pavel Dohnal
2020-06-23 13:09:10 +02:00
committed by Veljko V
parent 754172982a
commit 14713265b3
7 changed files with 74 additions and 15 deletions

View File

@ -2,6 +2,7 @@
namespace MailPoet\API\JSON\v1;
use MailPoet\AdminPages\Pages\FormEditor;
use MailPoet\API\JSON\Endpoint as APIEndpoint;
use MailPoet\API\JSON\Error as APIError;
use MailPoet\Config\AccessControl;
@ -86,7 +87,14 @@ class Forms extends APIEndpoint {
]);
}
public function create() {
public function create($data = []) {
if (isset($data['template-id']) && isset(FormEditor::TEMPLATES[$data['template-id']])) {
return $this->save(
$this->formFactory->createFormFromTemplate(
FormEditor::TEMPLATES[$data['template-id']]
)
);
}
return $this->save($this->formFactory->createEmptyForm());
}