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

Fix compatibility with wp-graphql-gutenberg-acf #114

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

Conversation

jonsherrard
Copy link

@jonsherrard jonsherrard commented Jul 18, 2021

Simply casting the $attributes array to an object before running it though Schema validation
fails with ACF Pro's field groups. ACF outputs another nested array. Using JSON decode makes
sure that nested arrays are converted to objects as well.

There is also an issue with the HTML loader failing if there's no innerHTML defined in the block. HTML-less blocks are very useful for WordPress as a headless CMS with WPGraphQL.

I've added a check for empty HTML and added an empty span with a data-attr warning about the lack of innerHTML.

Simply casting the $attributes array to an object fails with ACF Pro's
field groups, as there's another nested array. Using JSON decode makes
sure that nested arrays are converted to objects as well

There is also an issue with the HTML loader failing if there's no
innerHTML defined in the block. HTML-less blocks are very useful for
WordPress as a headless CMS with WPGraphQL.
@@ -148,7 +148,13 @@ protected static function parse_attributes($data, $block_type) {

$validator = new Validator();

$result = $validator->schemaValidation((object) $attributes, $schema);
if (empty($data['innerHTML'])) {
$data['innerHTML'] = '<span data-warning="This block does not contain a render template"></span>';
Copy link
Owner

Choose a reason for hiding this comment

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

Could we leave there just an empty span and log this message with error_log and E_WARNING ?

Copy link
Author

Choose a reason for hiding this comment

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

Could do, but would need to conditionally call source_attributes with HtmlDomParser on L16, as that's what's causing the error. The DOM parser function error'so out when an empty string is passed in.

Copy link
Author

Choose a reason for hiding this comment

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

I'd also say, having played around, I'm not entirely sure about what innerHTML is, in an ACF defined Gutenberg block, versus a WP core block. And whether it's supposed to contain the HTML from render Template, do you know?

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.

2 participants