jameelmoses / acf-flexible-content-extended

Extends the ACF Flexible Content Field by transforming the layout list into a modal with image previews. Editing the fields layouts also happens in a modal for a better editing user experience.
Other
22 stars 9 forks source link

Preview missing for duplicated flexible layouts #11

Closed romanklabal closed 2 years ago

romanklabal commented 2 years ago

When you create a flexible layout, duplicate it (using the built-in ACF quick action) and then keep the fields intact in the copy by just renaming them, they keep their internal key. Thats means they are being mistakenly skipped as duplicates by this retrieve_flexible_keys_from_fields() check in /classes/main.php:

if ( ! empty( $keys[ $layout_field['key'] ] ) ) {

and ignored, which means the preview for any but the most recent layouts is missing.

I have fixed it by combining the parent layout key (which does change upon duplication) with the field key so the key is really unique, like this:

if ( ! empty( $field['key'] . '-' . $layout_field['key'] ] ) ) {
    continue;
}
$keys[ $field['key'] . '-' . $layout_field['key'] ] = $layout_field['name'];

Happy to provide you with an example or with a PR if you'd like.

jameelmoses commented 2 years ago

@romanklabal thanks for reporting. i'd gladly review a PR