mc-acf-flexible-template
mc-acf-flexible-template copied to clipboard
Can't save or load from clone
Bug Description
When a flexible content field is loaded in to another group via ACF's built-in clone
field the plugin struggles to load or save templates for the given field.
Reproduce
- Create a "Component Selector" ACF group with a single flexible content field.
- add some example layouts to the flexible content field
- Create a "Layout Builder" ACF group with a single repeater field.
- in the repeater field, add a
clone
field - set the Fields option to our
Component Selector (all fields)
- make sure that the Display options is set to "seamless"
- in the repeater field, add a
- Create a new post
- create a "layout" in our repeater
- add some "components" to our inner flexible content field
Expected Behavior
I'd expect to see the load/save buttons above each "component" (which I do!) and be able to, well.... use them. That is, to be able to save and then load any given component layout as a template.
The "actual behavior" when I try to save one of my component's is to give a bit of vague messaging (see screenshot) and then nothing... nor does the template get added to the "ACF Templates" tab...
This is probably a pretty complex/inane ACF setup — the plugin works great in the simpler scenarios I tested! Still, it'd be very useful for me in this particular instance. So if you do have a chance to work out this kink it'd be much appreciated. (Happy to help if/where I can...)
Screenshots
the error when I try to "Save" a layout template
Versions
-
WordPress:
v4.9.6
-
ACF: ACF Pro,
v5.7.0
-
ACF Add Ons
- Repeater Field
v2.1.0
- Flexible Content Field,
v2.1.0
- Repeater Field
Hi @rafegoldberg I think it's the same issue that https://github.com/MarieComet/mc-acf-flexible-template/issues/8 which I can't resolve for now.
I gotchya. In any case, let me say again that this is an awesome plugin! It addresses a sorely missed functionality in ACF's core. Very cool.
Adding the following code block after line 351 in mc-acf-flexible-template.php
fixes the issue for flexible fields that are inside a clone field. It doesn't fix #8, but it could also be fixed easily in similar fashion.
if ( ! $fields && ! empty( $_POST['acf'] ) && is_array( $_POST['acf'] ) ) {
foreach ( $_POST['acf'] as $field ) {
if ( ! is_array( $field ) )
continue;
foreach ( $field as $key => $value ) {
$length = strlen( $parent_key );
if ( substr( $key, -$length ) === $parent_key ) {
$fields = $value;
}
}
}
}
Hi @julesrenaud, do you think you can make a pull request for this fix ?
@MarieComet certainly, will do. Would you mind if I were to also do a second one which makes it optional to register the acf_template_tax
taxonomy? It can be confusing for the user to see "Uncategorized" in the UI.
Adding the following code block after line 351 in
mc-acf-flexible-template.php
fixes the issue for flexible fields that are inside a clone field. It doesn't fix #8, but it could also be fixed easily in similar fashion.if ( ! $fields && ! empty( $_POST['acf'] ) && is_array( $_POST['acf'] ) ) { foreach ( $_POST['acf'] as $field ) { if ( ! is_array( $field ) ) continue; foreach ( $field as $key => $value ) { $length = strlen( $parent_key ); if ( substr( $key, -$length ) === $parent_key ) { $fields = $value; } } } }
You mention possibly being able to use this as a fix for #8, which has been something that I have been struggling with for some time. Can you create a PR to fix #8 too?
Thanks @julesrenaud!
@PseudoPsychosis I believe so. I think the solution I'm working on will fix both issues. I will post a PR soon.
@PseudoPsychosis I believe so. I think the solution I'm working on will fix both issues. I will post a PR soon.
You rock. Thank you!
Any update on a fix? desperately want to be able to use this plugin
It's been a few years but it seems that there was a PR for this that was never merged here https://github.com/MarieComet/mc-acf-flexible-template/pull/14
@CalebBarnes PR #14 is not related to this issue ("Make acf template tax optional") : https://github.com/MarieComet/mc-acf-flexible-template/pull/14/commits/1d09c88af3f42594cdf48f444ef3bce584516119