Hi @psykro
Thanks for replying to both my questions!
Here’s the same block code that I shared on my other question:
First, there’s a php file where I set things up. In there I have this code:
class JSXBlock {
function __construct($name, $renderCallback = null) {
$this->name = $name;
$this->renderCallback = $renderCallback;
add_action('init', [$this, 'onInit']);
}
function ourRenderCallback($attributes, $content) {
ob_start();
require get_theme_file_path("/template-parts/blocks/{$this->name}/{$this->name}.php");
return ob_get_clean();
}
function onInit() {
wp_register_script($this->name, get_stylesheet_directory_uri() . "/build/{$this->name}.js", array('wp-blocks', 'wp-editor'));
$ourArgs = array(
'editor_script' => $this->name
);
if ($this->renderCallback) {
$ourArgs['render_callback'] = [$this, 'ourRenderCallback'];
}
register_block_type("ftm-blocks/{$this->name}", $ourArgs);
}
}
//
new JSXBlock('wv-h3', true);
Then I have this js in a separate file: wv-h3.js:
import { ToolbarGroup, ToolbarButton } from "@wordpress/components"
import { RichText, BlockControls } from "@wordpress/block-editor"
import { registerBlockType } from "@wordpress/blocks"
registerBlockType("ftm-blocks/wv-h3", {
title: "Heading level 3",
icon: 'heading',
category: "ftm-blocks",
keywords: ['heading', 'h3'],
attributes: {
text: { type: "string", default: "Type heading here"},
},
edit: EditComponent,
save: SaveComponent
})
function EditComponent(props) {
function handleTextChange(x) {
props.setAttributes({ text: x })
}
return (
<>
<RichText allowedFormats={["core/link"]} tagName="h3" className={<code>headline headline--l3</code>} value={props.attributes.text} onChange={handleTextChange} />
</>
)
}
function SaveComponent(props) {
return props.attributes.text
}
I also have a simple php file for render callback: wv-h3.php
<h3 class="wv-gb-h3">
<?php
echo $attributes['text'];
?>
</h3>
`I currently have two blocks made with this approach. I have also made several blocks that use the acf_register_block_type approach, as shown on the ACF website. These work well but share the same “unwanted transform options” issue with the blocks I constructed using the jsx approach.