-
Notifications
You must be signed in to change notification settings - Fork 809
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
WIP: Forms/update responses management #41602
base: trunk
Are you sure you want to change the base?
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! |
Are you an Automattician? The PR will need to be tested on WordPress.com. This comment will be updated with testing instructions as soon the build is complete. |
Code Coverage SummaryCoverage changed in 8 files. Only the first 5 are listed here.
3 files are newly checked for coverage.
|
36bb193
to
56200a2
Compare
b02f7a8
to
fcd67ca
Compare
* @param array $schema Schema array. | ||
* @return array Modified Schema array. | ||
*/ | ||
public function add_additional_fields_schema( $schema ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anton-vlasenko the PHP changes are the first pass, but is there a better way to do this?
We want to add more fields to the response object. It's also related to the prepare_item_for_response
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you could use something along the lines of WP_REST_Attachments_Controller::get_item_schema()
?
Since the Contact_Form_Endpoint
class extends WP_REST_Posts_Controller
, you could call parent::get_item_schema()
and then add your own fields to the schema - just as WP_REST_Attachments_Controller::get_item_schema()
does.
Personally, I don’t see a reason to override the add_additional_fields_schema
here.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a quick review of the PR (I understand it's still in draft). Thank you.
$post_ids = $request->get_param( 'post_ids' ); | ||
|
||
if ( $action && ! is_array( $post_ids ) ) { | ||
return new $this->error_response( __( 'Bad request', 'jetpack-forms' ), 400 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new $this->error_response( __( 'Bad request', 'jetpack-forms' ), 400 ); | |
return $this->error_response( __( 'Bad request', 'jetpack-forms' ), 400 ); |
This code calls a constructor on an object that has already been instantiated by error_response. This should result in a fatal error: https://3v4l.org/kKJYT.
'month' => intval( $row->month ), | ||
'year' => intval( $row->year ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: (int)
is faster than intval()
.
'month' => intval( $row->month ), | |
'year' => intval( $row->year ), | |
'month' => (int) $row->month, | |
'year' => (int) $row->year, |
$months | ||
), | ||
'source' => array_map( | ||
function ( $post_id ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function ( $post_id ) { | |
static function ( $post_id ) { |
return rest_ensure_response( | ||
array( | ||
'date' => array_map( | ||
function ( $row ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function ( $row ) { | |
static function ( $row ) { |
* @param array $schema Schema array. | ||
* @return array Modified Schema array. | ||
*/ | ||
public function add_additional_fields_schema( $schema ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you could use something along the lines of WP_REST_Attachments_Controller::get_item_schema()
?
Since the Contact_Form_Endpoint
class extends WP_REST_Posts_Controller
, you could call parent::get_item_schema()
and then add your own fields to the schema - just as WP_REST_Attachments_Controller::get_item_schema()
does.
Personally, I don’t see a reason to override the add_additional_fields_schema
here.
What do you think?
Fixes #41122
This is WIP right now and no reviews are needed. I'll update the description soon.
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: