pageRenderer = $pageRenderer; $this->customFieldsRepository = $customFieldsRepository; $this->customFieldsResponseBuilder = $customFieldsResponseBuilder; $this->formRenderer = $formRenderer; $this->dateBlock = $dateBlock; $this->wp = $wp; $this->formsFactory = $formsFactory; } public function render() { $id = (isset($_GET['id']) ? (int)$_GET['id'] : 0); if (isset($_GET['action']) && $_GET['action'] === 'create') { $form = $this->formsFactory->createEmptyForm(); $this->wp->wpSafeRedirect( $this->wp->getSiteUrl(null, '/wp-admin/admin.php?page=mailpoet-form-editor&id=' . $form->id() ) ); exit; } $form = Form::findOne($id); if ($form instanceof Form) { $form = $form->asArray(); } $form['styles'] = $this->formRenderer->getCustomStyles($form); $customFields = $this->customFieldsRepository->findAll(); $dateTypes = $this->dateBlock->getDateTypes(); $data = [ 'form' => $form, 'form_exports' => [ 'php' => Export::get('php', $form), 'iframe' => Export::get('iframe', $form), 'shortcode' => Export::get('shortcode', $form), ], 'pages' => Pages::getAll(), 'segments' => Segment::getSegmentsWithSubscriberCount(), 'styles' => $this->formRenderer->getCustomStyles($form), 'date_types' => array_map(function ($label, $value) { return [ 'label' => $label, 'value' => $value, ]; }, $dateTypes, array_keys($dateTypes)), 'date_formats' => $this->dateBlock->getDateFormats(), 'month_names' => $this->dateBlock->getMonthNames(), 'sub_menu' => 'mailpoet-forms', 'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields), 'preview_page_url' => $this->getPreviewPageUrl(), 'custom_fonts' => CustomFonts::FONTS, ]; $this->wp->wpEnqueueMedia(); $this->pageRenderer->displayPage('form/editor.html', $data); } private function getPreviewPageUrl() { $mailpoetPage = Pages::getDefaultMailPoetPage(); if (!$mailpoetPage) { return null; } $url = $this->wp->getPermalink($mailpoetPage); $params = [ Router::NAME, 'endpoint=' . FormPreview::ENDPOINT, 'action=' . FormPreview::ACTION_VIEW, ]; $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?') . join('&', $params); return $url; } }