<?php namespace MailPoet\Form; if (!defined('ABSPATH')) exit; use MailPoet\Entities\FormEntity; use MailPoet\Form\Templates\TemplateRepository; use MailPoet\Settings\SettingsController; class FormFactory { /** @var FormsRepository */ private $formRepository; /** @var TemplateRepository */ private $formTemplateRepository; /** @var SettingsController */ private $settings; public function __construct( FormsRepository $formRepository, TemplateRepository $formTemplateRepository, SettingsController $settings ) { $this->formRepository = $formRepository; $this->formTemplateRepository = $formTemplateRepository; $this->settings = $settings; } public function createFormFromTemplate(string $templateId, array $settings = []): FormEntity { if (!isset($settings['success_message'])) { $settings['success_message'] = $this->getDefaultSuccessMessage(); } $formTemplate = $this->formTemplateRepository->getFormTemplate($templateId); $formEntity = $formTemplate->toFormEntity(); $formSettings = $formEntity->getSettings() ?? []; $formEntity->setSettings(array_merge($formSettings, $settings)); $this->formRepository->persist($formEntity); $this->formRepository->flush(); return $formEntity; } public function createEmptyForm(): FormEntity { return $this->createFormFromTemplate(TemplateRepository::INITIAL_FORM_TEMPLATE); } private function getDefaultSuccessMessage() { if ($this->settings->get('signup_confirmation.enabled')) { return __('Check your inbox or spam folder to confirm your subscription.', 'mailpoet'); } return __('You’ve been successfully subscribed to our newsletter!', 'mailpoet'); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Block | Folder | 0755 |
|
|
Listing | Folder | 0755 |
|
|
Templates | Folder | 0755 |
|
|
Util | Folder | 0755 |
|
|
ApiDataSanitizer.php | File | 1.82 KB | 0644 |
|
AssetsController.php | File | 3.38 KB | 0644 |
|
BlockStylesRenderer.php | File | 3.79 KB | 0644 |
|
BlockWrapperRenderer.php | File | 548 B | 0644 |
|
BlocksRenderer.php | File | 3.98 KB | 0644 |
|
DisplayFormInWPContent.php | File | 7.77 KB | 0644 |
|
FormFactory.php | File | 1.69 KB | 0644 |
|
FormHtmlSanitizer.php | File | 1.11 KB | 0644 |
|
FormMessageController.php | File | 1.61 KB | 0644 |
|
FormSaveController.php | File | 1021 B | 0644 |
|
FormsRepository.php | File | 2.52 KB | 0644 |
|
PreviewPage.php | File | 3.91 KB | 0644 |
|
PreviewWidget.php | File | 472 B | 0644 |
|
Renderer.php | File | 4.05 KB | 0644 |
|
Widget.php | File | 8.34 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|