Home › Forums › Gutenberg › Convert Gutenberg paragraph block to ACF-registered textarea block › Reply To: Convert Gutenberg paragraph block to ACF-registered textarea block
Sooo, i finally managed to found a way of achieve this.
First, you need to modify the way you register the block in ACF.
You’ll have to add “transform” in your acf_register_block() call
(All the needed code is in the Gist)
Then, the PHP will pass your transformers “transform” method as a string, not a callable function, so we need to convert it.
Then, in my transformer function, I receive an object with the string content, and there it is the ugliest part, (I don’t find any solution to pass content directly to the createBlock method for ACF block, maybe ACF can tell us?)
I use a setInterval to wait the ACF block is loaded in the DOM and I put the content into my field.
You can find all the code here:
SO: I know it’s an ugly and hacky way to achieve this, but I didn’t find any other way (except rebuild my Block without ACF but it wasn’t an option) and it seem’s to work.. I imagine for people who know better the ACF & Gutenberg API than me there are some other and better ways to do..
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.