Add automatic nl2br switch to custom html settings

[MAILPOET-2462]
This commit is contained in:
Rostislav Wolny
2019-12-11 13:44:36 +01:00
committed by Pavel Dohnal
parent a577680122
commit 906307a2c7
7 changed files with 20 additions and 2 deletions

View File

@@ -14,6 +14,10 @@ export const settings = {
type: 'string',
default: MailPoet.I18n.t('blockCustomHtmlDefault'),
},
nl2br: {
type: 'boolean',
default: true,
},
},
supports: {
html: false,

View File

@@ -3,6 +3,7 @@ import {
Panel,
PanelBody,
TextareaControl,
ToggleControl,
} from '@wordpress/components';
import { InspectorControls } from '@wordpress/block-editor';
import PropTypes from 'prop-types';
@@ -20,6 +21,11 @@ const CustomHtmlEdit = ({ attributes, setAttributes }) => {
rows={4}
onChange={(content) => setAttributes({ content })}
/>
<ToggleControl
label={MailPoet.I18n.t('blockCustomHtmlNl2br')}
checked={attributes.nl2br}
onChange={(nl2br) => (setAttributes({ nl2br }))}
/>
</PanelBody>
</Panel>

View File

@@ -92,6 +92,7 @@ export default (blocks) => {
static: '0',
params: {
text: block.attributes && block.attributes.content ? block.attributes.content : '',
nl2br: block.attributes && block.attributes.nl2br ? '1' : '0',
},
};
default:

View File

@@ -75,6 +75,7 @@ export default (data) => {
name: 'mailpoet-form/custom-html',
attributes: {
content: item.params && item.params.text ? item.params.text : '',
nl2br: item.params && item.params.nl2br ? !!item.params.nl2br : false,
},
};
default: