MarieComet / mc-acf-flexible-template

WordPress plugin makes it possible to save the ACF flexible content fields as templates
71 stars 19 forks source link

Can't save or load from clone #10

Open rafegoldberg opened 6 years ago

rafegoldberg commented 6 years ago

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

  1. Create a "Component Selector" ACF group with a single flexible content field.
    • add some example layouts to the flexible content field
  2. Create a "Layout Builder" ACF group with a single repeater field.
    • in the repeater field, add a clone field
    • set the Fields option to ourComponent Selector (all fields)
    • make sure that the Display options is set to "seamless"
  3. 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

image the error when I try to "Save" a layout template

Versions

MarieComet commented 6 years ago

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.

rafegoldberg commented 6 years ago

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.

julesrenaud commented 5 years ago

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;
            }
        }
    }
}
MarieComet commented 5 years ago

Hi @julesrenaud, do you think you can make a pull request for this fix ?

julesrenaud commented 5 years ago

@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.

PseudoPsychosis commented 5 years ago

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!

julesrenaud commented 5 years ago

@PseudoPsychosis I believe so. I think the solution I'm working on will fix both issues. I will post a PR soon.

PseudoPsychosis commented 5 years ago

@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!

sethwhitaker commented 5 years ago

Any update on a fix? desperately want to be able to use this plugin

CalebBarnes commented 2 years ago

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

MarieComet commented 2 years ago

@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