Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Helper/Helper_Options_Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],

Expand Down Expand Up @@ -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',
],
Expand Down
15 changes: 13 additions & 2 deletions src/Rest/Rest_Form_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/unit-tests/Rest/Test_Rest_Form_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down