Skip to content
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

Can't save or load from clone #10

Open
rafegoldberg opened this issue Jul 29, 2018 · 11 comments
Open

Can't save or load from clone #10

rafegoldberg opened this issue Jul 29, 2018 · 11 comments
Labels
bug help wanted bug I can't fix myself, help wanted

Comments

@rafegoldberg
Copy link

rafegoldberg commented Jul 29, 2018

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

  • WordPress: v4.9.6
  • ACF: ACF Pro, v5.7.0
  • ACF Add Ons
    • Repeater Field v2.1.0
    • Flexible Content Field, v2.1.0
@MarieComet
Copy link
Owner

Hi @rafegoldberg
I think it's the same issue that #8 which I can't resolve for now.

@rafegoldberg
Copy link
Author

rafegoldberg commented Jul 29, 2018

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
Copy link

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
Copy link
Owner

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

@julesrenaud
Copy link

@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
Copy link

PseudoPsychosis commented Nov 6, 2018

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
Copy link

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

@PseudoPsychosis
Copy link

@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
Copy link

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

@MarieComet MarieComet added bug wontfix help wanted bug I can't fix myself, help wanted and removed wontfix labels May 16, 2019
@CalebBarnes
Copy link

It's been a few years but it seems that there was a PR for this that was never merged here #14

@MarieComet
Copy link
Owner

@CalebBarnes PR #14 is not related to this issue ("Make acf template tax optional") : 1d09c88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted bug I can't fix myself, help wanted
Projects
None yet
Development

No branches or pull requests

6 participants