Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejackson1 committed Aug 29, 2024
1 parent d0befb7 commit c4ec3f2
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 89 deletions.
21 changes: 14 additions & 7 deletions src/Rest/Rest_Form_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,16 @@ public function prepare_item_for_response( $item, $request ) {
$context = ! empty( $request->get_param( 'context' ) ) ? $request->get_param( 'context' ) : 'edit';

$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );

$data = apply_filters( 'gfpdf_form_settings_rest_prepared_response', $data, $request );
/* Get the links before the data is filtered */
$links = $this->prepare_links( $data );

/* Wrap the data in a response object. */
$data = $this->filter_response_by_context( $data, $context );
$data = apply_filters( 'gfpdf_form_settings_rest_prepared_response', $data, $request );
$response = rest_ensure_response( $data );

if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$response->add_links( $this->prepare_links( $request, $data ) );
$response->add_links( $links );
}

return $response;
Expand Down Expand Up @@ -1096,14 +1097,20 @@ protected function get_section_schema( $settings, $group ) {
}

/**
* @param \WP_REST_Request $request
* @param array $data
* Add links for PDF setting
*
* @param array $data
*
* @return array[]
*
* @since 6.12.0
*/
protected function prepare_links( $request, $data ) {
protected function prepare_links( $data ) {

if ( ! isset( $data['form'], $data['id'] ) ) {
return [];
}

$links = [
'self' => [
'href' => rest_url( sprintf( '%s/%d/%s', static::get_route_basepath(), $data['form'], $data['id'] ) ),
Expand Down
Loading

0 comments on commit c4ec3f2

Please sign in to comment.