Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Images not found if Flexible field is in a Repeater field #7

Closed
tmconnect opened this issue May 16, 2018 · 7 comments
Closed

Images not found if Flexible field is in a Repeater field #7

tmconnect opened this issue May 16, 2018 · 7 comments
Labels
enhancement New feature or request need tests

Comments

@tmconnect
Copy link

First of all: Great work!

But the images for the popup are not found if the Flexible field is in a Repeater field.

I found a solution for an existing scenario on my site, but I don't know if this is the correct way for all. I changed the foreach ( $fields as $field ) loop in the retrieve_flexible_keys function to this:

foreach ( $fields as $field ) {
	if ( 'repeater' === $field['type'] ) {
		foreach ($field['sub_fields'] as $repeaterfield) {
			if ( 'flexible_content' === $repeaterfield['type'] ) {
				foreach ( $repeaterfield['layouts'] as $layout_field ) {
					$keys[ $layout_field['key'] ] = $layout_field['name'];
				}							
			}
		}
	} else if ( 'flexible_content' === $field['type'] ) {
		// Flexible is recursive structure with sub_fields into layouts
		foreach ( $field['layouts'] as $layout_field ) {
			if ( $keys [ $layout_field ] ) {
				continue;
			}
			$keys[ $layout_field['key'] ] = $layout_field['name'];
		}
	}
}

Hope, this helps for further development.

Thomas

@MaximeCulea MaximeCulea self-assigned this May 17, 2018
@MaximeCulea MaximeCulea added the enhancement New feature or request label May 17, 2018
@MaximeCulea
Copy link
Contributor

Hi @tmconnect,

To clarify a little bit, you are using flexible fields into a repeater one ?

Thank you for your kindness and code proposal.

@tmconnect
Copy link
Author

Thanks for your reply.

Yes - I have a "pagebuilder system" which has a repeater where the user can add rows to build his page. Within this repeater - and therefore in each row - is a flexible content field with a lots of layouts the user can select from.

@MaximeCulea
Copy link
Contributor

Great ! I'll have a look closely soon then.

@MaximeCulea
Copy link
Contributor

MaximeCulea commented Jun 4, 2018

Hi @tmconnect,
Sorry for the delay, I had some hollidays 🤗

Could you please check that this version (https://github.com/BeAPI/bea-beautiful-flexible/archive/issue-7.zip) include your changes and works well in your case ?

You will be kind, thank you 😄

@tmconnect
Copy link
Author

Thanks for the new version, but I got an error - even if the flexible content field is not in repeater:
Illegal offset type in .../wp-content/plugins/bea-beautiful-flexible-issue-7/classes/main.php on line 85

After delving a bit deeper into your code, I found a much simpler solution for the implementation:

Because each popup item already has a data-layout attribute, which tells the name of the layout element. You don't have to get the names of all flexible layouts in an extra function.

The JS script only has to get this data-layout attribute and has to modify the acf-popup list. In addition I wrote some data attributes to the acf-popup element for the title and subtitle for the popup. So the strings can be translated.

You can download my solution from my dropbox: Link

Let me know if this works for you.

Thomas

@MaximeCulea
Copy link
Contributor

Hi @tmconnect,
It seems that this error was already present and now fixed with #10.
Except this error, everything was fine ?
Please let me now in order to merge and release.
Thx

@MaximeCulea MaximeCulea removed their assignment Feb 25, 2020
@herewithme
Copy link
Member

This plugin is deprecated.
I recommend you to use : https://wordpress.org/plugins/acf-extended/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request need tests
Projects
None yet
Development

No branches or pull requests

3 participants