Skip to content

Commit f8329d7

Browse files
committed
Differentiate between checkbox and toggles
1 parent 7521ef1 commit f8329d7

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/Helper/Helper_Options_Fields.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function get_registered_fields() {
338338
'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' ),
339339
'schema' => [
340340
'type' => 'boolean',
341-
'format' => 'yes_no',
341+
'format' => 'yes-no',
342342
],
343343
],
344344

@@ -636,7 +636,7 @@ public function get_registered_fields() {
636636
'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' ),
637637
'default' => false,
638638
'required' => false,
639-
'format' => 'yes_no',
639+
'format' => 'yes-no',
640640
'arg_options' => [
641641
'sanitize_callback' => 'rest_sanitize_request_arg',
642642
],

src/Rest/Rest_Form_Settings.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,15 @@ protected function prepare_item_for_database( $request ) {
837837
}
838838

839839
/* Handle Toggle values */
840-
if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'yes_no' ) {
840+
if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'yes-no' ) {
841841
$value = $value === true ? 'Yes' : 'No';
842842
}
843843

844+
/* Handle checkbox values */
845+
if ( $this->has_property_type( 'boolean', $property['type'] ) && ( $property['format'] ?? '' ) === 'checkbox' ) {
846+
$value = $value === true ? '1' : '';
847+
}
848+
844849
$prepared_pdf[ $id ] = $value;
845850
}
846851

@@ -1092,9 +1097,15 @@ protected function get_section_schema( $settings, $group ) {
10921097
break;
10931098

10941099
case 'checkbox':
1100+
$schema[ $id ]['type'] = 'boolean';
1101+
$schema[ $id ]['format'] = 'checkbox';
1102+
$schema[ $id ]['default'] = in_array( $default, [ 'Yes', '1', 1, 'true', true ], true );
1103+
$schema[ $id ]['arg_options']['sanitize_callback'] = 'rest_sanitize_request_arg';
1104+
break;
1105+
10951106
case 'toggle':
10961107
$schema[ $id ]['type'] = 'boolean';
1097-
$schema[ $id ]['format'] = 'yes_no';
1108+
$schema[ $id ]['format'] = 'yes-no';
10981109
$schema[ $id ]['default'] = in_array( $default, [ 'Yes', '1', 'true', true ], true );
10991110
$schema[ $id ]['arg_options']['sanitize_callback'] = 'rest_sanitize_request_arg';
11001111

tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public function test_get_item_schema() {
819819
$this->assertContains( 'landscape', $args['orientation']['enum'] );
820820

821821
$this->assertSame( 'boolean', $args['rtl']['type'] );
822-
$this->assertSame( 'yes_no', $args['rtl']['format'] );
822+
$this->assertSame( 'yes-no', $args['rtl']['format'] );
823823

824824
$this->assertContains( 'Standard', $args['format']['enum'] );
825825
$this->assertContains( 'PDFX1A', $args['format']['enum'] );

0 commit comments

Comments
 (0)