Hi!
I noticed a problem when I create custom blocks that contain <InnerBlocks/>. In that case, I am not able to retrieve the $block object in the js script fired in the backend.
function.php
——————
add_action('init', 'register_acf_blocks');
function register_acf_blocks() {
wp_register_script('accordion-script', get_stylesheet_directory_uri() . '/blocks/accordion/script.js');
register_block_type(get_template_directory() . '/blocks/accordion/block.json');
}
block.json
————–
{
"name": "accordion",
"title": "Accordion",
"description": "Accordion to hide large amounts of text in drop-down sections.",
"category": "my-category",
"icon": "media-code",
"keywords": [
"accordion"
],
"acf": {
"mode": "preview",
"renderTemplate": "render.php"
},
"script": "accordion-script",
"supports": {
"layout": false,
"align": false,
"customClassName": false
},
"example": {
"viewportWidth": 800
}
}
render.php
—————-
<InnerBlocks/>
script.js
———–
(function($){
var initializeBlock = function($block) {
console.log($block); // HERE IS THE PROBLEM!!! IN CONSOLE: e.<computed> {length: 0, prevObject: e.<computed>}
}
if( window.acf ) {
window.acf.addAction( 'render_block_preview/type=accordion', initializeBlock );
}
})(jQuery);
The problem disappears when I insert any HTML instead of InnerBlocks in render.php
WP version: 6.8.1
ACF version 6.4.2