diff --git a/src/Helper/Helper_Options_Fields.php b/src/Helper/Helper_Options_Fields.php index 2d0d1cb73..6c3181ede 100644 --- a/src/Helper/Helper_Options_Fields.php +++ b/src/Helper/Helper_Options_Fields.php @@ -338,7 +338,7 @@ public function get_registered_fields() { 'desc2' => esc_html__( 'Add rules to dynamically enable or disable the PDF. When disabled, PDFs do not show up in the admin area, cannot be viewed, and will not be attached to notifications.', 'gravity-forms-pdf-extended' ), 'schema' => [ 'type' => 'boolean', - 'format' => 'yes_no', + 'format' => 'yes-no', ], ], @@ -636,7 +636,7 @@ public function get_registered_fields() { 'description' => __( 'Force the PDF to be temporarily saved to the filesystem during form submission (deprecated). Use the gfpdf_post_save_pdf hook instead.', 'gravity-forms-pdf-extended' ), 'default' => false, 'required' => false, - 'format' => 'yes_no', + 'format' => 'yes-no', 'arg_options' => [ 'sanitize_callback' => 'rest_sanitize_request_arg', ], diff --git a/src/Rest/Rest_Form_Settings.php b/src/Rest/Rest_Form_Settings.php index 2823761b0..4c5df1380 100644 --- a/src/Rest/Rest_Form_Settings.php +++ b/src/Rest/Rest_Form_Settings.php @@ -837,10 +837,15 @@ protected function prepare_item_for_database( $request ) { } /* Handle Toggle values */ - if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'yes_no' ) { + if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'yes-no' ) { $value = $value === true ? 'Yes' : 'No'; } + /* Handle checkbox values */ + if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'checkbox' ) { + $value = $value === true ? '1' : ''; + } + $prepared_pdf[ $id ] = $value; } @@ -1092,9 +1097,15 @@ protected function get_section_schema( $settings, $group ) { break; case 'checkbox': + $schema[ $id ]['type'] = 'boolean'; + $schema[ $id ]['format'] = 'checkbox'; + $schema[ $id ]['default'] = in_array( $default, [ 'Yes', '1', 1, 'true', true ], true ); + $schema[ $id ]['arg_options']['sanitize_callback'] = 'rest_sanitize_request_arg'; + break; + case 'toggle': $schema[ $id ]['type'] = 'boolean'; - $schema[ $id ]['format'] = 'yes_no'; + $schema[ $id ]['format'] = 'yes-no'; $schema[ $id ]['default'] = in_array( $default, [ 'Yes', '1', 'true', true ], true ); $schema[ $id ]['arg_options']['sanitize_callback'] = 'rest_sanitize_request_arg'; diff --git a/tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php b/tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php index 6e4e6817c..243bb03e7 100644 --- a/tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php +++ b/tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php @@ -819,7 +819,7 @@ public function test_get_item_schema() { $this->assertContains( 'landscape', $args['orientation']['enum'] ); $this->assertSame( 'boolean', $args['rtl']['type'] ); - $this->assertSame( 'yes_no', $args['rtl']['format'] ); + $this->assertSame( 'yes-no', $args['rtl']['format'] ); $this->assertContains( 'Standard', $args['format']['enum'] ); $this->assertContains( 'PDFX1A', $args['format']['enum'] );