Gutenberg block JavaScript localisation on Polyglots does not work

The first argument $handle of wp_set_script_translations() expects the script handle the text domain will be attached to. In your case it’s simpletoc and not simpletoc-js. The correct call would be: wp_set_script_translations( ‘simpletoc’, ‘simpletoc’ ); Another note: wp_set_script_translations() is available since WordPress 5.0 thus the function_exists() check isn’t necessary.

can a buttongroup have a label?

I have discovered a way of creating a label and a help property for a component that doesn’t have it’s own label or help properties, by wrapping that component in a BaseControl component. Here is my working solution: createElement(PanelRow, {}, createElement(BaseControl, { label: __(‘N element alignment’, ‘my-textdomain’), help: __(‘Set the alignment for n element in … Read more

event/callback on block update?

You might try a useEffect hook subscribed to the attributes.identifier to call the script. something like: function Edit( { attributes, setAttributes } ) { useEffect( () => { // this will fire whenever the attribute changes. thirdPartyScriptFunctionName(); },[attributes.identifier]) const onChangeIdentifier = (value) => { setAttributes({ identifier: value }); }; return ( <div id = {`embed-${ … Read more

Block Validation Fails: ‘

I solved the problem by rendering my block’s content, a component, to a string and making that string the value of a RichText component in my block’s save function. To make my component a string, I used renderToString: // Create the content and the block const myContent = ( <MyComponent>{“Some content”}</MyComponent> ); const myBlock = … Read more

How to get the parent of a non-hierarchical custom post type being edited in Gutenberg

You are already using the correct Gutenberg/JS code, but it’s a limitation in the REST API which exposes the parent field only for hierarchical post types like page. But you can force the field to appear in the REST API responses via register_rest_field() — example for a my_cpt post type: register_rest_field( ‘my_cpt’, ‘parent’, array( ‘schema’ … Read more