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

for ACF Gutenberg: does not return chosen format on preview (e.g. array), but only the attachment post id #72

Open
elmarbransch opened this issue Apr 17, 2020 · 1 comment

Comments

@elmarbransch
Copy link

elmarbransch commented Apr 17, 2020

This is not a duplicate of #51 and #52 - we checked this tickets and applied the suggested PR as well.
If you use ACF Gutenberg (create Gutenberg Blocks using ACF PHP API) there are two states:

  1. Edit state: presenting the ACF edit form
  2. Preview state: presenting the rendered content

In both states is_admin() is true, but in edit state ACF expects the return value to be the attachment id only, in contrast in preview state it should be the formatted value (e.g. array).

At the moment we did not yet find a way to check for edit-vs-preview in the plugin hook. But ACF will inject a variable $is_preview into the render template code. This is our only hint so far.

Maybe someone has smart approach for this?

@elmarbransch elmarbransch changed the title for ACF: does not return chosen format (e.g. array), but only the attachment post id for ACF Gutenberg: does not return chosen format on preview (e.g. array), but only the attachment post id Apr 17, 2020
@elmarbransch
Copy link
Author

While browsing the acf pro code we checked the handling of the $is_preview var and it looks like this can be derived in the same way inside our hook in this plugin.

if ( ! is_admin() ) {
...
}
else {
	// code as seen in advanced-customfields-pro/pro/blocks.php::acf_ajax_fetch_block()
	extract(acf_request_args(array('query'=>array())));
	if( isset($query['preview']) && $query['preview'] == 'true' ) {
		switch_to_media_site();
		$image = $this->transform_acf_to_return_format( $field['return_format'], $value );
		restore_current_blog();
	}
}

Here is the relevant code portion for filter_acf_attachment_load_value()

Sorry for not providing a clean PR here ...
Best
Elmar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant