Home › Forums › Front-end Issues › align_content/alignContent in ACF 6.x
I tried to create this as a support ticket, but after two days I’m guessing the team has its plate full with ACF 6.x bugs. So here it is for the forum
….
I have a number of ACF based blocks using the matrix
content align option.
As described in the ACF 6.x upgrade notes this attribute will change from “align_content” to “alignContent”, but after updating (on dev, of course) it doesn’t exist as neither “align_content” nor “alignContent”. They are both simply empty when I get them from the template that renders the block.
Even if “align_content” has a value for the block when checking it in the database, it looks like the the ACF rendering function removes it.
If I edit the page I see “align_content” still exist as an attribute on the block in Gutenberg code editor, and if I switch back to preview and return to code “align_content” is replaced with “alignContent” – which is fine, I guess.
But, this requires me to edit all pages for them to have the correct value in “alignContent”.
These functions acf_get_block_back_compat_attribute_key_array
and acf_add_back_compat_attributes
in wp-content/plugins/advanced-custom-fields-pro/pro/blocks.php
apparently should handle backwards compatibility for rendering, but the syntax isn’t logical and only changes something id there is a value in “alignContent” ….which there never will be for blocks made with versions prior to 6.0
function acf_add_back_compat_attributes( $block ) {
foreach ( acf_get_block_back_compat_attribute_key_array() as $new => $old ) {
if ( isset( $block[ $new ] ) ) {
$block[ $old ] = $block[ $new ];
}
}
return $block;
}
As a very, very, very temporary solution I added a placeholder attribute before rendering the block, and I can use it in the template to make my own check for a legacy value
function acf_legacy_attributes_missing( $parsed_block, $source_block, $parent_block ) {
$parsed_block['attrs']['align_content_acf_legacy'] = ( !empty( $parsed_block['attrs']['align_content'] ) ? $parsed_block['attrs']['align_content'] : '' );
$parsed_block['attrs']['align_text_acf_legacy'] = ( !empty( $parsed_block['attrs']['align_text'] ) ? $parsed_block['attrs']['align_text'] : '' );
$parsed_block['attrs']['id'] = ( !empty( $parsed_block['attrs']['id'] ) ? $parsed_block['attrs']['id'] : 'block_id_' . uniqid() );
return $parsed_block;
}
add_filter( "render_block_data", "acf_legacy_attributes_missing", 10, 3 );
This adds the attribute align_content_acf_legacy
, align_text_acf_legacy
and ID
holding the old values.
So, my questions is – did I miss something in the upgrade notes or is this simply a ACF 6.x bug?
You must be logged in to reply to this topic.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.