Render form after it is added to the page
[MAILPOET-1798]
This commit is contained in:
committed by
Jack Kitterhing
parent
9fcb189295
commit
6befd09423
@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable react/react-in-jsx-scope */
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
const wp = window.wp;
|
||||||
|
const ServerSideRender = wp.serverSideRender;
|
||||||
const allForms = window.mailpoet_forms;
|
const allForms = window.mailpoet_forms;
|
||||||
|
|
||||||
function Edit({ attributes, setAttributes }) {
|
function Edit({ attributes, setAttributes }) {
|
||||||
@ -26,10 +28,28 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderForm() {
|
||||||
|
return (
|
||||||
|
<ServerSideRender
|
||||||
|
block="mailpoet/form-block-render"
|
||||||
|
attributes={{ form: attributes.selectedForm }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mailpoet-block-div">
|
<div className="mailpoet-block-div">
|
||||||
<h2>MailPoet Subscription Form</h2>
|
<h2>MailPoet Subscription Form</h2>
|
||||||
{displayFormsSelect()}
|
{
|
||||||
|
attributes.selectedForm === null && (
|
||||||
|
displayFormsSelect()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
attributes.selectedForm !== null && (
|
||||||
|
renderForm()
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
use MailPoet\Form\FormsRepository;
|
use MailPoet\Form\FormsRepository;
|
||||||
|
use MailPoet\Form\Widget;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class PostEditorBlock {
|
class PostEditorBlock {
|
||||||
@ -32,7 +33,7 @@ class PostEditorBlock {
|
|||||||
$this->wp->wpEnqueueScript(
|
$this->wp->wpEnqueueScript(
|
||||||
'mailpoet-block-form-block-js',
|
'mailpoet-block-form-block-js',
|
||||||
Env::$assetsUrl . '/dist/js/' . $this->renderer->getJsAsset('post_editor_block.js'),
|
Env::$assetsUrl . '/dist/js/' . $this->renderer->getJsAsset('post_editor_block.js'),
|
||||||
['wp-blocks', 'wp-components'],
|
['wp-blocks', 'wp-components', 'wp-server-side-render'],
|
||||||
Env::$version,
|
Env::$version,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -49,6 +50,16 @@ class PostEditorBlock {
|
|||||||
'editor_script' => 'mailpoet/form-block',
|
'editor_script' => 'mailpoet/form-block',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
register_block_type( 'mailpoet/form-block-render', [
|
||||||
|
'attributes' => [
|
||||||
|
'form' => [
|
||||||
|
'type' => 'number',
|
||||||
|
'default' => null,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'render_callback' => [$this, 'renderForm'],
|
||||||
|
]);
|
||||||
|
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
add_action('admin_head', function() {
|
add_action('admin_head', function() {
|
||||||
$forms = $this->formsRepository->findAllNotDeleted();
|
$forms = $this->formsRepository->findAllNotDeleted();
|
||||||
@ -62,4 +73,15 @@ class PostEditorBlock {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderForm($attributes) {
|
||||||
|
if (!$attributes) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$basicForm = new Widget();
|
||||||
|
return $basicForm->widget([
|
||||||
|
'form' => (int)$attributes['form'],
|
||||||
|
'form_type' => 'html',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user