Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
413 stars 56 forks source link

Renaming ACF blocks automatically #151

Closed rikhen closed 1 year ago

rikhen commented 1 year ago

Image I have created a block via $ wp acorn acf:block HelloWorld" and started using this block on a page. For some reason, I now want to change the title of the block to "ByeWorld". So I manually rename the app\Blocks\HelloWorld.php to ByWorld.php, change its class name to ByeWorld and all the related functions and finally rename the \resources\views\blocks\hello-world.blade.php to bye-world.blade.php.

When reloading the page with the block, I obviously get the error Your site doesn’t include support for the "acf/hello-world" block. You can leave this block intact or remove it entirely.. So I have to delete the old block and insert the new block, but I have to start from scratch.

By any change, is there a way to do this in an automated command (for example via the cli) without losing data?

Log1x commented 1 year ago

Unfortunately this is a limitation of Gutenberg. If you were to rename/remove a native block, it would suffer the same issue without writing a transformation for it (which isn't possible with ACF).

If you edit your post with Gutenberg's code editor, you'll see how it stores the block data directly inside of the post content:

<!-- wp:acf/company-overview {"name":"acf/company-overview","data":{"name":"Example","_name":"field_company_overview_name"}} -->`

It's possible you could search-replace the block name as well as the block prefix (in this case, acf/company-overview and field_company_overview) with WP-CLI but I'm not sure if there's anything else at play that would prevent it from working. This would get extra complicated if you were to rename any of the field groups.

More or less, I'd try to avoid this situation if you can help it. 😅

rikhen commented 1 year ago

Alright. I imagined it had nothing to do with the ACF composer itself. Thanks for the superfast reply, @Log1x!