Add mapper for mapping blocks to form body data

[MAILPOET-2451]
This commit is contained in:
Rostislav Wolny
2019-12-02 17:16:04 +01:00
committed by Jack Kitterhing
parent 4e71908332
commit c9d73f6970
2 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
export default (blocks) => {
let position = 1;
return blocks.map((block) => {
const mapped = {
params: {},
};
switch (block.name) {
case 'mailpoet-form/email-input':
mapped.id = 'email';
mapped.type = 'text';
mapped.unique = '0';
mapped.static = '1';
mapped.name = 'Email';
mapped.params.label = block.attributes.label;
mapped.params.required = '1';
if (block.attributes.labelWithinInput) {
mapped.params.label_within = '1';
}
break;
case 'mailpoet-form/submit-button':
mapped.id = 'submit';
mapped.type = 'submit';
mapped.name = 'Submit';
mapped.unique = '0';
mapped.static = '1';
mapped.params.label = block.attributes.label;
break;
default:
return null;
}
mapped.position = position.toString();
position += 1;
return mapped;
}).filter(Boolean);
};