Add form preview page form rendering
[MAILPOET-2743]
This commit is contained in:
committed by
Veljko V
parent
db618d7948
commit
0b512fe81b
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Router\Endpoints;
|
||||
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Form\PreviewPage;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class FormPreview {
|
||||
@ -15,31 +16,35 @@ class FormPreview {
|
||||
/** @var array|null */
|
||||
private $data;
|
||||
|
||||
/** @var PreviewPage */
|
||||
private $formPreviewPage;
|
||||
|
||||
public $allowedActions = [self::ACTION_VIEW];
|
||||
public $permissions = [
|
||||
'global' => AccessControl::NO_ACCESS_RESTRICTION,
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
WPFunctions $wp
|
||||
WPFunctions $wp,
|
||||
PreviewPage $formPreviewPage
|
||||
) {
|
||||
$this->wp = $wp;
|
||||
$this->formPreviewPage = $formPreviewPage;
|
||||
}
|
||||
|
||||
public function view(array $data) {
|
||||
$this->data = $data;
|
||||
$this->wp->addFilter('the_content', [$this,'renderContent'], 10);
|
||||
$this->wp->addFilter('the_title', [$this,'renderTitle'], 10);
|
||||
$this->wp->addFilter('the_title', [$this->formPreviewPage,'renderTitle'], 10);
|
||||
$this->wp->addFilter('show_admin_bar', function () {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public function renderContent(): string {
|
||||
return '<h1>Todo render form</h1>';
|
||||
}
|
||||
|
||||
public function renderTitle(): string {
|
||||
return __('Sample page to preview your form', 'mailpoet');
|
||||
if (!isset($this->data['id']) || !isset($this->data['form_type'])) {
|
||||
return '';
|
||||
}
|
||||
return $this->formPreviewPage->renderPage((int)$this->data['id'], (string)$this->data['form_type']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user