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

[gatsby-source-wordpress] improve linking acf fields to media nodes #2646

Closed
wants to merge 12 commits into from

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Oct 26, 2017

this makes matching acf fields to media nodes more flexible and adds support for ACF gallery field

it was tested with structure like this:

ACF root
 - Image (return URL)
 - Image (return Image Data)
 - Gallery
 - Post Object
   - featured_media
 - Repeater
   - Image (return URL)
   - Image (return Image Data)
   - Gallery
   - Post Object
     - featured_media
   - Flexible Content (nested in repeater)
     - Image (return URL)
     - Image (return Image Data)
     - Gallery
 - Flexible Content
   - Image (return URL)
   - Image (return Image Data)
   - Gallery
   - Post Object
     - featured_media
   - Repeater (nested in flexible content)
     - Image (return URL)
     - Image (return Image Data)
     - Gallery

And this is diff of graphql schema (manually edited, exporting schema to file would be extra handy if I would know how) after applying changes in this PR - https://gist.github.com/pieh/876c8e7a47b11a3609b379e10628068c.

pieh added 11 commits October 26, 2017 16:53
… to media node:

 - if value is photo url - find media with that url
 - if value is ACF Image Object - get url from image object and find media with that url
This allow for using either Image Object or Image URL in ACF fields configuration.
Previously it had very specific configuration requierments that image in root acf group had to return Image URL, but image in flexible content had to return Image Object
…nObject and adjust returned value

we always have to delete featured_media even if we can't find image for it
now it doesn't make assumptions about structure, so we can just pass root acf field (possibly just root entity) and don't worry about root specific structure - this allow to have repeater field in root acf field (previously it had to be nested in flexible layout, cause of specific checks that were done on root acf field).
…tead of media node

this will allow easily hookup discovering and replaceing acf gallery arrays with media node arrays
@gatsbybot
Copy link
Collaborator

gatsbybot commented Oct 26, 2017

Deploy preview ready!

Built with commit 982f95c

https://deploy-preview-2646--gatsbygram.netlify.com

@KyleAMathews
Copy link
Contributor

The using-wordpress site seems to be working just fine https://deploy-preview-2646--using-wordpress.netlify.com/

@sebastienfi could you review this?

@pieh
Copy link
Contributor Author

pieh commented Oct 26, 2017

Note: I will be away from home until monday or tuesday. I just rushed this PR, bacause i had this ready. Ideally I would like to add some documentation https://www.gatsbyjs.org/packages/gatsby-source-wordpress/ about image processing when i come back.

@KyleAMathews
Copy link
Contributor

@pieh awesome! Lots to do with gatsby-source-wordpress so the more helpers the merrier!

@sebastienfi
Copy link
Contributor

sebastienfi commented Oct 27, 2017

@pieh @KyleAMathews I will definitely test this PR.

@pieh Could you please test the PR I submitted at the same moment ? #2648

I have tested mine against a pretty similar ACF datamodel, I'm curious to see if it works with your model as it is. I have abstracted the media checks so it applies to any JSON node, including those outside of ACF field, and improved the recursivity of the function so that a photo could be placed higher in the three. (let's say an Image in a Repeater, inside a Clone with group not seemless, ...)

@pieh
Copy link
Contributor Author

pieh commented Oct 27, 2017

@sebastienfi For most part it does work. Just not ACF gallery. Your changes are actually similiar to mine, I just separated matching fields to images and traversing + replacing nodes to different functions and you traverse from entity root.

Only thing really missing for me is support for gallery field - you can do it like that - pieh@163719f .

Plus I still hit build error described in comments here - cd0eb2b#comments

sebastienfi added a commit that referenced this pull request Oct 27, 2017
* Most of the credits goes to @pieh for a better solution that solved the same problems and widely improved code simplicity. #2646
* Made the Media lookup begin at JSON tree root instead of keeping this for ACF Field only. Changed constants names accordingly.
* Making thise more generic allorws Custom Post Types to benefit from this improvements and yet unseen objects shapes. 
* Incorporated fix on bug mentionned here #2646 (comment)
* May solve this #2587, this #2492, this #2328
@sebastienfi
Copy link
Contributor

Actually I found that your code was more readable so I pulled your code and build from it. Thanks a lot !
Could you please give a go to the current solution and tell me if it works for you ?
#2648

sebastienfi added a commit that referenced this pull request Oct 27, 2017
#2648)

* Refactored featured_media map for deep nodes

* Featured medias coul be nested at any level
* The most certain way to have photos works with this version on the plugin is to either name the fiel featured_media or include the image as Post Object.
* Fixed bug where in some case the old featured_media field was not deleted.

* Update normalize.js.snap

* Integrated pieh 's changes

* Most of the credits goes to @pieh for a better solution that solved the same problems and widely improved code simplicity. #2646
* Made the Media lookup begin at JSON tree root instead of keeping this for ACF Field only. Changed constants names accordingly.
* Making thise more generic allorws Custom Post Types to benefit from this improvements and yet unseen objects shapes. 
* Incorporated fix on bug mentionned here #2646 (comment)
* May solve this #2587, this #2492, this #2328

* Update normalize.js.snap
@ryancoughlin
Copy link

Been trying to dig around the schema tree for an example on how to query various image types and other types via GraphQL (with ACF). Strings, etc. work great, I can't seem to query images though.

Do you have any examples or documentation to breakdown various queries with ACF? I am using the starter and that was very helpful.

Happy to open a PR against the starter README

@KyleAMathews
Copy link
Contributor

Have you checked out the using-wordpress example site?

@ryancoughlin
Copy link

ryancoughlin commented Nov 12, 2017 via email

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.

5 participants