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

Add support for ACF Blocks #327

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jasonbahl
Copy link
Contributor

  • update get_acf_field_value() to use the value if the $root is an array that has a key matching the acf field name
  • update get_acf_field_value() to resolve fields from blocks using acf_setup_meta / acf_reset_meta
  • update docblock / spacing for register_graphql_field
  • update resolver for relationship field to compensate for root data coming in different shapes
  • update resolver for image/file fields to use loader and compensate for root data in different shapes
  • update resolver for gallery field to compensate for root data passed in different shapes
  • update resolver for user field to use the deferred loader
  • update get_all_graphql_types function to include blocks as locations that a field group can be assigned

…ray that has a key matching the acf field name

- update get_acf_field_value() to resolve fields from blocks using acf_setup_meta / acf_reset_meta
- update docblock / spacing for register_graphql_field
- update resolver for relationship field to compensate for root data coming in different shapes
- update resolver for image/file fields to use loader and compensate for root data in different shapes
- update resolver for gallery field to compensate for root data passed in different shapes
- update resolver for user field to use the deferred loader
- update get_all_graphql_types function to include blocks as locations that a field group can be assigned

// @see: https://support.advancedcustomfields.com/forums/topic/getting-get_field-outside-block-loop/#post-84022
$block_id = isset( $root['attrs']['id'] ) ? $root['attrs']['id'] : null;
acf_setup_meta( $root['attrs']['data'], $block_id, true );
Copy link

@lgladdy lgladdy Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $block_id is null here, then acf_setup_meta won't return data for the get_fields call below.

I think you could swap this line (and 391 and 392) to:

$fields = acf_setup_meta( $root['attrs']['data'] );

to support both ACF5 and ACF6's upcoming changes - no need for get_fields() as acf_setup_meta will return the fields for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgladdy hmm. Making that change breaks for me.

This is something that will only work on v6?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be... that logic hasn't been change. I'll test further!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, acf_setup_meta doesn't build and return the right structure for repeater (and repeater like) fields, so that's why it's erroring.

Instead of that route, changing from a null block_id to a random block_{random-id} will solve the issue for ACF6.

@codysign
Copy link

codysign commented May 4, 2023

Any updates on this topic?

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

Successfully merging this pull request may close these issues.

None yet

3 participants