Add data to template
[MAILPOET-3120]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user