Move Template Selection to a separate page
[MAILPOET-2987]
This commit is contained in:
@ -38,7 +38,7 @@ class FormEditor {
|
||||
'params' => ['label' => 'Email', 'class_name' => '', 'required' => '1'],
|
||||
'id' => 'email',
|
||||
'name' => 'Email',
|
||||
'styles' => ['full_width' => '1']
|
||||
'styles' => ['full_width' => '1'],
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
@ -47,7 +47,7 @@ class FormEditor {
|
||||
'name' => 'First name',
|
||||
'styles' => ['full_width' => '1'],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'column',
|
||||
@ -191,12 +191,12 @@ class FormEditor {
|
||||
}
|
||||
|
||||
public function render() {
|
||||
if (!isset($_GET['id']) && !isset($_GET['action'])) {
|
||||
if (!isset($_GET['id']) && !isset($_GET['action'])) {
|
||||
$this->renderTemplateSelection();
|
||||
return;
|
||||
}
|
||||
if (isset($_GET['action']) && $_GET['action'] === 'create') {
|
||||
$this->createForm($_GET['template-id']);
|
||||
$this->createForm();
|
||||
}
|
||||
$form = Form::findOne((int)$_GET['id']);
|
||||
if ($form instanceof Form) {
|
||||
@ -233,7 +233,7 @@ class FormEditor {
|
||||
$this->pageRenderer->displayPage('form/editor.html', $data);
|
||||
}
|
||||
|
||||
private function renderTemplateSelection() {
|
||||
public function renderTemplateSelection() {
|
||||
$templates = array_values(self::TEMPLATES);
|
||||
if (empty($templates) || !$this->flagsController->isSupported(FeaturesController::TEMPLATES_SELECTION)) {
|
||||
$this->createForm();
|
||||
@ -244,13 +244,8 @@ class FormEditor {
|
||||
$this->pageRenderer->displayPage('form/template_selection.html', $data);
|
||||
}
|
||||
|
||||
private function createForm($templateId = null) {
|
||||
if (!is_null($templateId) && isset(self::TEMPLATES[$templateId])) {
|
||||
$form = $this->formsFactory->createFormFromTemplate(self::TEMPLATES[$templateId]);
|
||||
}
|
||||
if (!isset($form)) {
|
||||
$form = $this->formsFactory->createEmptyForm();
|
||||
}
|
||||
private function createForm() {
|
||||
$form = $this->formsFactory->createEmptyForm();
|
||||
|
||||
$this->wp->wpSafeRedirect(
|
||||
$this->wp->getSiteUrl(null,
|
||||
|
@ -188,6 +188,26 @@ class Menu {
|
||||
});
|
||||
});
|
||||
|
||||
// form editor templates
|
||||
$formTemplateSelectionEditorPage = $this->wp->addSubmenuPage(
|
||||
true,
|
||||
$this->setPageTitle(__('Form Editor', 'mailpoet')),
|
||||
$this->wp->__('Form Editor', 'mailpoet'),
|
||||
AccessControl::PERMISSION_MANAGE_FORMS,
|
||||
'mailpoet-form-editor-template-selection',
|
||||
[
|
||||
$this,
|
||||
'formEditorTemplateSelection',
|
||||
]
|
||||
);
|
||||
|
||||
// add body class for form editor page
|
||||
$this->wp->addAction('load-' . $formTemplateSelectionEditorPage, function() {
|
||||
$this->wp->addAction('admin_body_class', function ($classes) {
|
||||
return ltrim($classes . ' block-editor-page');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Subscribers page
|
||||
$subscribersPage = $this->wp->addSubmenuPage(
|
||||
@ -454,6 +474,10 @@ class Menu {
|
||||
$this->container->get(FormEditor::class)->render();
|
||||
}
|
||||
|
||||
public function formEditorTemplateSelection() {
|
||||
$this->container->get(FormEditor::class)->renderTemplateSelection();
|
||||
}
|
||||
|
||||
public function setPageTitle($title) {
|
||||
return sprintf(
|
||||
'%s - %s',
|
||||
|
@ -5,6 +5,10 @@ namespace MailPoet\Form;
|
||||
use MailPoet\Models\Form;
|
||||
|
||||
class FormFactory {
|
||||
/**
|
||||
* @param array $template
|
||||
* @return Form
|
||||
*/
|
||||
public function createFormFromTemplate(array $template) {
|
||||
if (isset($template['id'])) {
|
||||
unset($template['id']);
|
||||
|
@ -21,7 +21,7 @@
|
||||
<% autoescape 'js' %>
|
||||
var mailpoet_templates = <%= json_encode(templates) %>;
|
||||
var mailpoet_form_edit_url =
|
||||
"<%= admin_url('admin.php?page=mailpoet-form-editor&action=create&template-id=') %>";
|
||||
"<%= admin_url('admin.php?page=mailpoet-form-editor&id=') %>";
|
||||
<% endautoescape %>
|
||||
</script>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
var mailpoet_listing_per_page = <%= items_per_page %>;
|
||||
var mailpoet_segments = <%= json_encode(segments) %>;
|
||||
var mailpoet_form_edit_url =
|
||||
"<%= admin_url('admin.php?page=mailpoet-form-editor') %>";
|
||||
"<%= admin_url('admin.php?page=mailpoet-form-editor-template-selection') %>";
|
||||
var mailpoet_beacon_articles = [
|
||||
'5e43d3ec2c7d3a7e9ae79da9',
|
||||
'5e3a166204286364bc94dda4',
|
||||
|
Reference in New Issue
Block a user