Add data to template

[MAILPOET-3120]
This commit is contained in:
Pavel Dohnal
2020-09-03 14:20:02 +02:00
committed by Veljko V
parent 50ebace032
commit 5c21da80d5
3 changed files with 52 additions and 2 deletions

View File

@@ -154,7 +154,7 @@ class FormEditor {
'iframe' => Export::get('iframe', $form),
'shortcode' => Export::get('shortcode', $form),
],
'pages' => Pages::getAll(),
'mailpoet_pages' => Pages::getAll(),
'segments' => Segment::getSegmentsWithSubscriberCount(),
'styles' => $this->formRenderer->getCustomStyles($form),
'date_types' => array_map(function ($label, $value) {
@@ -170,6 +170,10 @@ class FormEditor {
'preview_page_url' => $this->getPreviewPageUrl(),
'custom_fonts' => CustomFonts::FONTS,
'translations' => $this->getGutenbergScriptsTranslations(),
'posts' => $this->getAllPosts(),
'pages' => $this->getAllPages(),
'categories' => $this->getAllCategories(),
'tags' => $this->getAllTags(),
];
$this->wp->wpEnqueueMedia();
$this->pageRenderer->displayPage('form/editor.html', $data);
@@ -254,4 +258,42 @@ class FormEditor {
}
return $translations;
}
private function getAllPosts() {
return $this->formatPosts($this->wp->getPosts());
}
private function getAllPages() {
return $this->formatPosts($this->wp->getPages());
}
private function getAllCategories() {
return $this->formatTerms($this->wp->getCategories());
}
private function getAllTags() {
return $this->formatTerms($this->wp->getTags());
}
private function formatPosts($posts) {
$result = [];
foreach ($posts as $post) {
$result[] = [
'id' => $post->ID,
'name' => $post->post_title,// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
];
}
return $result;
}
private function formatTerms($terms) {
$result = [];
foreach ($terms as $term) {
$result[] = [
'id' => $term->term_id,// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
'name' => $term->name,
];
}
return $result;
}
}

View File

@@ -160,6 +160,10 @@ class Functions {
return get_categories($args);
}
public function getTags($args = '') {
return get_tags($args);
}
public function getComment($comment = null, $output = OBJECT) {
return get_comment($comment, $output);
}

View File

@@ -23,7 +23,7 @@
var mailpoet_form_data = <%= json_encode(form) %>;
var mailpoet_form_exports = <%= json_encode(form_exports) %>;
var mailpoet_form_segments = <%= json_encode(segments) %>;
var mailpoet_form_pages = <%= json_encode(pages) %>;
var mailpoet_form_pages = <%= json_encode(mailpoet_pages) %>;
var mailpoet_custom_fields = <%= json_encode(custom_fields) %>;
var mailpoet_date_types = <%= json_encode(date_types) %>;
var mailpoet_date_formats = <%= json_encode(date_formats) %>;
@@ -31,6 +31,10 @@
var mailpoet_form_preview_page = <%= json_encode(preview_page_url) %>;
var mailpoet_custom_fonts = <%= json_encode(custom_fonts) %>;
var mailpoet_translations = <%= json_encode(translations) %>;
var mailpoet_all_wp_posts = <%= json_encode(posts) %>;
var mailpoet_all_wp_pages = <%= json_encode(pages) %>;
var mailpoet_all_wp_categories = <%= json_encode(categories) %>;
var mailpoet_all_wp_tags = <%= json_encode(tags) %>;
var mailpoet_close_icons_url = '<%= image_url("form_close_icon") %>';
<% endautoescape %>
</script>