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

Components: withAPIData: Don't restrict to /wp/v2, allow custom endpoints #3536

Closed
wants to merge 1 commit into from

Conversation

mcsf
Copy link
Contributor

@mcsf mcsf commented Nov 17, 2017

Description

Fixes #3209

How Has This Been Tested?

  1. Set up a site with the appropriate branches of Sensei and Sensei Courses according to the instructions in the parent issue. Set up a post/page in Gutenberg according to the instructions and use the Network inspector.
  2. Make sure that a successful request to /sensei/v1/courses is found alongside the request to /wp/v2/course-category.
  3. Make sure core blocks aren't affected by this (e.g. Latest Posts), nor other consumers of withAPIData within the framework (e.g. sidebar controls).

/cc @donnapep

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@mcsf mcsf requested a review from aduth November 17, 2017 19:27
@mcsf mcsf added the Framework Issues related to broader framework topics, especially as it relates to javascript label Nov 17, 2017
wp_json_encode( $schema_response->get_data() )
wp_json_encode( array(
'namespace' => '',
'routes' => $schema_response->get_data()[ 'routes' ],
Copy link
Member

Choose a reason for hiding this comment

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

Per failing test:

Function array dereferencing is not present in PHP version 5.3 or earlier (PHPCompatibility.PHP.NewFunctionArrayDereferencing.Found)

Further, why do we need to do this change at all? Can we not just encode the data as we had done previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, but the data has a different shape. Instead of getting an object with keys ( namespace, routes ), we have keys ( name, description, url, home, gmt_offset, timezone_string, namespaces, authentication, routes, permalink_structure ). Note the plural namespaces. Hence the sort-of-faking happening here. How do you suggest proceeding? We can indeed pass the entire data and handle it differently on the client.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can recall, withAPIData really only cares about the routes property, and if we assume the schema response' routes includes all registered routes, all the better. Other keys can simply be ignored.

Copy link
Contributor

@donnapep donnapep Dec 3, 2017

Choose a reason for hiding this comment

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

I've tested this change both as-is and by reverting the encoding changes as per some discussion with @aduth . Works great!

I can submit a separate PR, but thought it might be easier for someone with commit access to make the change in this PR and put the encoding stuff back in. Cheers!

Never mind. I really need this so I've created PR #3778. Thx.

@greatislander
Copy link
Contributor

Related: #3462

@aduth
Copy link
Member

aduth commented Dec 3, 2017

Superseded by #3778

@aduth aduth closed this Dec 3, 2017
@aduth aduth deleted the update/with-api-data-all-root-namespace branch December 4, 2017 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withAPIData does not work with custom endpoints
4 participants