-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing the ACF PRO Block Versioning Developer Preview #654
Comments
This is great news, thanks for the hard work thus far! I have a few quick questions that will likely help others test as well.
I can't wait to test out the v2 markup changes :) |
Specifically: "style": "file:./all-fields-block.css", That's loading a file called "all-fields-block.css" in the same folder as the block.json whenever the block is added to a page.
I'll look into this a bit deeper to see if we can manually add support for it, but that might not be possible for other reasons that is specific to the block.json loading. |
Okay great, thanks.
|
@JiveDig Yeh - we definitely will get migration guides and such in the release documentation. Let me know if you need any help though. For my own dev test blocks I actually just copy/pasted the PHP array and converted it to JSON format, but you could always do: echo json_encode($block_configuration_array, JSON_PRETTY_PRINT);
die(); to get the start point out from the PHP code for the old way! |
I got ya. I was thinking |
@lgladdy it seems there is something broken with the default I have registered a block like this:
In a specific post I have used this block and the Before the new alpha version, everything looks good with the alignment. After using the new alpha now this It seems there is something wrong and should be improved. |
@lgladdy For now, the change from removing block IDs looks good. The block IDs no longer exist. I have copied some ACF blocks and made changes to each copied block and it seems there are no longer issues with the field values was set to a wrong block. But this issue #605 is still there: May-13-2022.08-58-41.mp4It only works properly after the post has been saved and reloaded. But not if the block was only inserted after copying. Then correct field changes are not present. Is there any hope to get this fixed? |
@lgladdy the
This id is no longer used for allocating ACF blocks. Thank you! But will this attribute remain in the |
Yup - the block ID is just a hash of the attributes, but we need to keep |
Thanks, I'll look into this one. This is probably because we also turned "align_text" into "alignText"; our upgrade code probably picked up the default value over the set value and didn't change it. |
@lgladdy The "Block Versioning" is a very good idea to handle the issue with the block markup. Thank you! I can confirm the markup for inner blocks is now more simple than before: Block version 1: <div class="block-editor-inner-blocks">
<div class="block-editor-block-list__layout" data-is-drop-zone="true">
... innerBlocks ...
</div>
</div> Block version 2: <div class="acf-inner-blocks-container block-editor-block-list__layout" data-is-drop-zone="true">
... innerBlocks ...
</div> This looks good and is the first way in the right direction. Thank you. But we can't wait for the complete change to make the ACF block markup more simple also for the ACF block itself. :-) Here is another question to the markup. It seems there is no way to remove the I asking because, CSS selectors like " BUT, only ONE additional ACF container is better than a lot of additional ACF containers. With only one additional ACF container it's more easier to the handle this thing by " |
Could you remake this video with console open too? For this test, we're logging all the internal IDs (which WordPress handles now) along with all the requests that take place to the renderer, so we should be able to figure out what's happening; but this does point to it being a Gutenberg bug now WordPress is responsible for handling block IDs. |
Honestly, I don't think we'll get any simpler than we have now, until WordPress introduce new features (like they did which let us fix the As for removing the container, nope - that's not possible for the same reasons. Gutenberg (via React) uses the container to know where things can be dragged/dropped etc, and where the "Add New" buttons should appear etc. |
@lgladdy I like the new way to register ACF block in the Block.json way. I will test this soon. |
@lgladdy Yes, that's what I thought. I think we can deal with that. Because now, in this case, it's just a container. What is still missing is the markup simplification for the ACF block itself. |
May-13-2022.09-57-22.mp4@lgladdy Here is the full log of the console: I hope this is helping you. |
@lgladdy ok, this means we have to change nothing here right? |
@lgladdy Currently I'm trying to test the new feature to load ACF blocks via the block.json file, but I'm having trouble with the script assets: Using Using I get the following message. register_block_script_handle was called incorrectly. The asset file for the "script" defined in "acf/documentation-menu" block definition is missing. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) This JS file exists and the path is correct. What is wrong here? |
@lgladdy I want to ask you if
I have worked out that both methods should be supported:
In other words, |
@lgladdy I was wondering if a solution would make sense for ACF to automatically create a block.json file for each block using |
You'd likely need to look into the WordPress source here to see what filters/action it fires at each point you're looking to do something custom. We've found that there does tend to be filters and actions at most sensible points, so it should be possible!
This is dependant on WordPress's support for it, you can see that by each line of their documentation at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/ or the block schema. Currently
We'll support it as long as WordPress does - which should be for the foreseeable future, but you're likely going to notice things like asset enqueuing breaking before that support goes, as the WordPress enqueue system for blocks doesn't work unless you use block.json. We'll investigate if we can backport it into You may also miss out of new features that WordPress brings, as it's starting to put code exclusively in the block.json parsing functions. Remember, this change is dictated by WordPress rather than us. There are filters you can use to modify block.json too if you wanted to use PHP functions to set things like svg icons. |
I'll take a look at this - that looks sensible to me, unless there's another |
There exists no other script like this. I have tried to load the script directly in the block directory or to load in a sub folder of the block directly. Each time I will get this notice. By investigating this:
I can see the |
I suspect the performance of re-initing everything for a block might be too much - especially as we'd need to load things like select2 and date/time pickers etc. Essentially the full ACF stack including third party libraries. My hope is the back compat mode they're working on won't have any downsides to us opting into for all ACF blocks - as it will run those blocks like it does now. |
@lgladdy I just tested it. It may be possible to specify an ACF dependency and ACF scripts will then load in tablet/mobile preview. Yes, there are probably many scripts that ACF needs to load. But theoretically that could be a workaround if there is no other option in the future. But I suspect that there will be a possibility through Wordpress. |
@lgladdy I have a question. Is there a way inside an inner block to find out which block type is the parent? So far I only know the way to query an ACF field of the parent block via "providesContext", whether it exists or not. But I don't like this solution. |
@CreativeDive I actually don't know if you could set a fixed string to pass through to providesContext? I'll take a look once we've shipped 6.0 and get back to you! |
@CreativeDive Actually, wait... we store |
@lgladdy Thanks very much! A nice way! That's exactly what I needed and it works. A helpful note for the ACF block documentation. |
@lgladdy I have an additional question. Should |
Struggling with
|
@JiveDig I solved it like this: $field = my_acf_parent_block_field( 'field_name', $context );
if ( ! function_exists( 'my_acf_parent_block_field' ) ) :
function my_acf_parent_block_field( $field_name, $context ) {
// Get the parent block ACF fields from $context if provided
$context = isset( $context['acf/fields'] ) ? $context['acf/fields'] : array();
// Get the correct field, depending on the "field_name" or "field_key" is passed
$context_data = acf_setup_meta( $context );
// Get the field value
$value = isset( $context_data[$field_name] ) ? $context_data[$field_name] : '';
// Get the field object
$field = get_field_object( $field_name );
// Get the formatted value if exists
$value = apply_filters( 'acf/format_value', $value, '', $field );
return $value;
}
endif; |
@CreativeDive That looks nice. Have you tested that when I'd still love to be able to add my own data to |
@JiveDig No, I haven't tried it for repeater data. I think getting this to work with repeater data isn't the problem. But I can't say more about it because I use it in a small area of field data. |
Definitely looks like repeater data isn't working as expected here. |
@lgladdy (or anyone), is there a list of the things that can be passed to the child blocks via |
@JiveDig You can pass any data assigned to the block comment through with usesContext - so if you look in code view, any of the JSON keys you see there. This is all raw client side data though, which is why ACF can't do anything magical here to help you parse the data. To get around this, I suspect you could pass a second parameter to You can use just In the future, I'd expect we'll get some kind of |
@lgladdy This seems much more promising than manually getting the rows, but it seems to only return the first row. This works, but is messy:
This is cleaner but only gets the first row, or at least I think that's what's happening.
|
I'm hitting a new, and concerning issue. I have parent/child blocks, both built with ACF. Each child ACF block will often have identical settings, but the markup needs to be different, based on the parent block settings as well as the current index/item. I'm finding out that if the child blocks have identical settings it seems they are cached/hashed and rendered without parsing again, which breaks my output. If I dump/debug in my callback for each child block, only the first one triggers anything at all. Is there a way to force everything from parsing, even if the child block settings are the same? |
It also seems that I need to save a block change, then refresh the editor, for it to re-parse the block and display correctly. Maybe I'm just not understanding how ACF is handling each child block and I can handle things in my code to make it work, or maybe it's a bug or FR for ACF? |
Okay weird. this parent/child thing seems to only happen in the editor. |
Yeah this is a tricky one. Since we can pass parent block settings to the child, there are definitely times where the parent settings will determine what happens in the child, so hashing like this will have issues. I love the performance benefits, but I'm hoping there is a fix, otherwise I'm back to the drawing board. |
@JiveDig I've been working on my WordPress theme for years now. The last few years have been very frustrating due to the many changes to WordPress. It somehow never ends. I'm glad that many pain points in ACF have been fixed. Still, the new "I can customize everything" thing seems to be a very tedious thing to do if you want to properly expand FSE. I'm still encountering issues I can't understand why WordPress didn't think things through properly. I can understand that very well. There is a lot of time in our work. |
@CreativeDive Sidenote, but related, are you in any WP Slack groups or somewhere we can chat? I pinged you on Twitter earlier. We're very aligned in our approach to things so it would be cool to keep in touch outside of ACF issues :D |
@JiveDig I've never used Slack, but can you send me a link to join? You can write me at [email protected] |
@CreativeDive It's been a public holiday in the UK today and Liam and Matt are both working extremely hard on the 6.0 release due very soon. I'm sure Liam will take a look when he can. |
It might be a good idea to try and keep new conversations off this issue so they don't get lost on the ever expanding thread. Feel free to open new individual issues. |
@polevaultweb sure, we know :-) Thanks for the information ! |
Introducing the ACF PRO Block Versioning Developer Preview
[Update 3, 20th July 2022]
We've released a forth developer preview build with some further bug fixes, you can find the details of those further changes here.
[Update 2, 27th June 2022]
We've released a third developer preview build, you can find the details of those further changes here.
[Update 9th June 2022]
We've released a second developer preview build, you can find details of the further changes in that release here.
In the last few releases of WordPress, Gutenberg has made significant changes to all aspects of the block editor and block registration, and many of you have raised issues and feature requests to improve ACF Blocks with those improvements.
For our next release of ACF, we’re aiming to bring some key new features to ACF Blocks to take advantage of those new features from Gutenberg, as well as improving existing blocks. We’re releasing a preview build today, early in our development cycle, so we can get your feedback and bug reports early in development.
You can download this preview (tagged as 6.0.0-alpha1) from your account now. This build is ACF PRO 5.12.2 with the following changes:
Block.json support
Since WordPress 5.8, WordPress has supported - and recommended - that blocks are registered through a JSON configuration file. All of the WordPress Block Documentation was migrated to only show block.json configuration objects, and it became confusing for users to know what WordPress configuration options were usable in ACF PRO. This build introduces support for block.json registration of blocks with ACF.
For blocks registered through a block.json file, you can mark them as ACF Blocks by adding a new ACF configuration key to the JSON file, which contains the ACF specific configuration, for example:
You then need to use the standard WordPress block registration function
register_block_type
, rather thanacf_register_block_type
:If you don't specify a namespace for your block like in our example above:
"name": "all-fields-block",
, ACF will automatically add it if it is an ACF block to become the equivalent of"name": "acf/all-fields-block",
Upon release, this new method of registering blocks will become the recommended way to register a block, replacing the
acf_register_block_type
function.The renderTemplate property should either be a full path to the template file, or relative to the location of the JSON file.
WordPress uses a camelCase format inside JSON files, and ACF adopts that too. Configuration keys such as
render_template
when used inacf_register_block_type
need to berenderTemplate
when used in JSON, likewisealign_content
andfull_height
should bealignContent
andfullHeight
for example. All previous configuration objects are supported, except forenqueue_style
,enqueue_script
andenqueue_assets
for the following reason:Asset Loading
When ACF Blocks was first introduced, it supported enqueueing block specific assets before WordPress had native support. Recent (and upcoming) updates to Gutenberg will require these assets to be loaded using specific WordPress asset configuration keys such as
editorScript
,script
,editorStyle
andstyle
.WordPress 5.9 users who use Block Styles may have noticed that the ACF registration of styles was not applied to those previews, which is why all ACF Block users should migrate their blocks to use those WordPress provided methods of asset loading.
The previous methods of asset loading in ACF Blocks will continue to work for the time being in
acf_register_block_type
, but as WordPress continues to make changes across releases we expect that to stop working.Block ID removal
This release of ACF will remove saved block IDs from ACF Blocks. This means you can easily copy and paste blocks, simplify your post type templates or block patterns, or duplicate blocks without having any issues where block IDs clash.
We’re hoping this change is transparent to users, and any existing blocks will have their block IDs removed the first time they’re edited after installing this build. We’ll still generate a
$block['id']
for your templates as we know some users use that for element IDs, but the format of those IDs will change, and may be duplicated if you have multiple blocks on the same page with the exact same data (similar to how block IDs are the same inside a query loop block now)Because of this, if you want to downgrade to ACF 5.12 after installing this build, you may experience warnings in your templates until you edit a block if you are relying on
$block['id']
in a template without checking if it exists.Block Versioning
One of the issues we’ve had with ACF Blocks development is that we haven’t been able to react to new Gutenberg features as fast as we’d like due to the requirement to maintain backwards compatibility with blocks created potentially as far back as WordPress 5.3.
This release of ACF brings block versioning, meaning we can make backwards compatibility breaking changes whenever necessary, allowing users to opt in to them to enable new features.
A new
blockVersion
(inside the ACF key in block.json) oracf_block_version
(if usingacf_register_block_type
) key is now supported. For blocks registered via block.json, this defaults to2
, and foracf_register_block_type
, this defaults to1
.For now, the only change between the two versions is the way
<InnerBlocks />
markup is rendered. If you use block version 2 (which requires WordPress 5.8+), the container markup when using InnerBlocks will match between backend and frontend rendering, with any inner blocks wrapped in a new (and single level)<div class="acf-inner-blocks-container"></div>
element. This can help make your CSS layouts easier, as you can be sure both render views have the same markup.Block Registry Standardization
In previous versions of ACF PRO, a lightweight shim of the block configuration was registered in PHP, and then the full configuration registered in JS.
In this build of ACF the full block configuration is now saved in the WordPress PHP Block Registry. This makes it easier for you to access details of the block configuration in your templates or render callback should you wish.
Block Bug Fixes
We’ve fixed a few reported bugs with ACF Blocks in this build as well. For example, content after
<InnerBlocks />
will now render correctly without the need to wrap it in anotherdiv
, andalignText
will now always default to the WordPress default ofleft
rather than an empty string.Wrap up
We hope you’ll take the time to test this build of ACF - we’re particularly interested in feedback on how your upgrades go to make sure there are no issues with the block ID removal system.
Please leave any comments, bugs or feedback here on this GitHub issue. We’ve left a few debug console messages in this build to try and help us detect any issues with block preloading or rendering, so screenshots of your browser console will likely be especially useful with any bug reports!
The text was updated successfully, but these errors were encountered: