WordPress Inject element into wp.element.createElement
-
I am working on a plugin that will allow us to add block options to the ACF block system and save the fields in meta. The issue is I am really rusty with js and I am unable to figure out how to merge my loop into the
wp.element.createsystem. I have included my javascript below with comments of what I am trying to accomplish. Any help on this is greatly appreciated.jQuery(function(){ var el = wp.element.createElement, Fragment = wp.element.Fragment registerBlockType = wp.blocks.registerBlockType, RichText = wp.editor.RichText, BlockControls = wp.editor.BlockControls, AlignmentToolbar = wp.editor.AlignmentToolbar, InspectorControls = wp.editor.InspectorControls; var withInspectorControls = wp.compose.createHigherOrderComponent( function( BlockEdit ) { return function( props ) { // Set data if it does not exist - needed when new page is created if(props.attributes.data === undefined){ props.attributes.data={}; } // begin creating the return element var elm = el( Fragment, {}, el( BlockEdit, props ), el( InspectorControls, {}, el( PanelBody, { title: 'Accordion Options' }, // THIS IS WHERE THE ADDED ELEMENTS WILL GO ) ); $.each(fields, function( key, field ) { switch(field.type){ case 'text': var optionField = el( TextControl, { label: field.label, help: field.instructions, onChange: function(value){ textField=value; props.setAttributes( { textField: value } ); } }); // ADD optionField TO elm ABOVE CORRECTLY break; default: continue; } }); return elm; }; }, 'withInspectorControls' ); wp.hooks.addFilter( 'editor.BlockEdit', 'acf/accordion', withInspectorControls ); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘WordPress Inject element into wp.element.createElement’ is closed to new replies.