Rename block attribute
[MAILPOET-1798]
This commit is contained in:
committed by
Jack Kitterhing
parent
831a865c9e
commit
62c5a8cc84
@ -17,11 +17,11 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
<select
|
<select
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setAttributes({
|
setAttributes({
|
||||||
selectedForm: parseInt(event.target.value, 10),
|
formId: parseInt(event.target.value, 10),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
className="mailpoet-block-create-forms-list"
|
className="mailpoet-block-create-forms-list"
|
||||||
value={attributes.selectedForm}
|
value={attributes.formId}
|
||||||
>
|
>
|
||||||
<option value="" disabled selected>{window.locale.selectForm}</option>
|
<option value="" disabled selected>{window.locale.selectForm}</option>
|
||||||
{allForms.map((form) => (
|
{allForms.map((form) => (
|
||||||
@ -36,8 +36,8 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
function renderForm() {
|
function renderForm() {
|
||||||
return (
|
return (
|
||||||
<ServerSideRender
|
<ServerSideRender
|
||||||
block="mailpoet/form-block-render"
|
block="mailpoet/subscription-form-block-render"
|
||||||
attributes={{ form: attributes.selectedForm }}
|
attributes={{ form: attributes.formId }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
<div className="mailpoet-block-div">
|
<div className="mailpoet-block-div">
|
||||||
{
|
{
|
||||||
attributes.selectedForm === null && (
|
attributes.formId === null && (
|
||||||
<Placeholder
|
<Placeholder
|
||||||
className="mailpoet-block-create-new"
|
className="mailpoet-block-create-new"
|
||||||
icon={<BlockIcon icon={Icon} showColors />}
|
icon={<BlockIcon icon={Icon} showColors />}
|
||||||
@ -77,7 +77,7 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
attributes.selectedForm !== null && (
|
attributes.formId !== null && (
|
||||||
renderForm()
|
renderForm()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ function Edit({ attributes, setAttributes }) {
|
|||||||
|
|
||||||
Edit.propTypes = {
|
Edit.propTypes = {
|
||||||
attributes: PropTypes.shape({
|
attributes: PropTypes.shape({
|
||||||
selectedForm: PropTypes.number,
|
formId: PropTypes.number,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
setAttributes: PropTypes.func.isRequired,
|
setAttributes: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ registerBlockType('mailpoet/form-block', {
|
|||||||
category: 'widgets',
|
category: 'widgets',
|
||||||
example: {},
|
example: {},
|
||||||
attributes: {
|
attributes: {
|
||||||
selectedForm: {
|
formId: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\PostEditorBlocks;
|
||||||
|
|
||||||
|
use MailPoet\Config\Env;
|
||||||
|
use MailPoet\Config\Renderer;
|
||||||
use MailPoet\Entities\FormEntity;
|
use MailPoet\Entities\FormEntity;
|
||||||
use MailPoet\Form\FormsRepository;
|
use MailPoet\Form\FormsRepository;
|
||||||
use MailPoet\Form\Widget;
|
use MailPoet\Form\Widget;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class PostEditorBlock {
|
class SubscriptionFormBlock {
|
||||||
/** @var Renderer */
|
/** @var Renderer */
|
||||||
private $renderer;
|
private $renderer;
|
||||||
|
|
||||||
@ -28,16 +30,7 @@ class PostEditorBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
// this has to be here until we drop support for WordPress < 5.0
|
$this->wp->registerBlockType('mailpoet/subscription-form-block-render', [
|
||||||
if (!function_exists('register_block_type')) return;
|
|
||||||
|
|
||||||
if (is_admin()) {
|
|
||||||
$this->initAdmin();
|
|
||||||
} else {
|
|
||||||
$this->initFrontend();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->wp->registerBlockType('mailpoet/form-block-render', [
|
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
'form' => [
|
'form' => [
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
@ -48,25 +41,10 @@ class PostEditorBlock {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initAdmin() {
|
public function initAdmin() {
|
||||||
$this->wp->wpEnqueueScript(
|
$this->wp->registerBlockType('mailpoet/subscription-form-block', [
|
||||||
'mailpoet-block-form-block-js',
|
|
||||||
Env::$assetsUrl . '/dist/js/' . $this->renderer->getJsAsset('post_editor_block.js'),
|
|
||||||
['wp-blocks', 'wp-components', 'wp-server-side-render', 'wp-block-editor'],
|
|
||||||
Env::$version,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->wp->wpEnqueueStyle(
|
|
||||||
'mailpoetblock-form-block-css',
|
|
||||||
Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset('post-editor-block.css'),
|
|
||||||
['wp-edit-blocks'],
|
|
||||||
Env::$version
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->wp->registerBlockType('mailpoet/form-block', [
|
|
||||||
'style' => 'mailpoetblock-form-block-css',
|
'style' => 'mailpoetblock-form-block-css',
|
||||||
'editor_script' => 'mailpoet/form-block',
|
'editor_script' => 'mailpoet/subscription-form-block',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->wp->addAction('admin_head', function() {
|
$this->wp->addAction('admin_head', function() {
|
||||||
@ -86,13 +64,13 @@ class PostEditorBlock {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initFrontend() {
|
public function initFrontend() {
|
||||||
$this->wp->registerBlockType('mailpoet/form-block', [
|
$this->wp->registerBlockType('mailpoet/subscription-form-block', [
|
||||||
'render_callback' => [$this, 'renderForm'],
|
'render_callback' => [$this, 'renderForm'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderForm($attributes) {
|
public function renderForm(array $attributes = []): string {
|
||||||
if (!$attributes || !isset($attributes['form'])) {
|
if (!$attributes || !isset($attributes['form'])) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -102,5 +80,4 @@ class PostEditorBlock {
|
|||||||
'form_type' => 'html',
|
'form_type' => 'html',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user