Skip to content

Commit

Permalink
Remove placeholder for the post-type option in Insert/Update post action
Browse files Browse the repository at this point in the history
Crocoblock/issues-tracker#3056
  • Loading branch information
girafffee committed Apr 18, 2024
1 parent cbdf1c5 commit c1713fc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ public function add_inserted_post_id() {
);
}

$post_type = $this->modifier->source_arr['post_type'] ?? '';

if ( ! $post_type ) {
$post_type = get_post_type( $this->inserted_id );
}

$inserted_key = jet_fb_context()->get_unique_name(
'inserted_' . $this->modifier->source_arr['post_type']
'inserted_' . $post_type
);

jet_fb_context()->update_request( $this->inserted_id, $inserted_key );
Expand Down
8 changes: 1 addition & 7 deletions includes/actions/types/insert-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,8 @@ public function action_data() {
);
}

$post_types = Tools::get_post_types_for_js();
$post_types[0] = array(
'label' => __( '-- Keep current (when updating post) --', 'jet-form-builder' ),
'value' => '',
);

return array(
'postTypes' => $post_types,
'postTypes' => Tools::get_post_types_for_js(),
'taxonomies' => Tools::get_taxonomies_for_modify(),
'postStatuses' => $this->get_post_statuses_for_options(),
'properties' => $properties,
Expand Down
47 changes: 47 additions & 0 deletions tests/wpunit/Actions/InsertPost/PostTypePropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Codeception\AssertThrows;
use Jet_Form_Builder\Actions\Methods\Post_Modification\Post_Modifier;
use Jet_Form_Builder\Actions\Methods\Post_Modification\Post_Type_Property;
use Jet_Form_Builder\Actions\Types\Insert_Post;
use Jet_Form_Builder\Exceptions\Action_Exception;
use Jet_Form_Builder\Exceptions\Silence_Exception;

Expand Down Expand Up @@ -103,5 +104,51 @@ public function testAllowChangePostType() {
$this->assertEquals( 'page', $property->get_value( $this->modifier ) );
}

public function testComputedNames() {
$action = new Insert_Post();
$action->_id = 7755;

jet_fb_action_handler()->save_action( $action, array() );

$action->settings = array(
'post_type' => 'page'
);

jet_fb_action_handler()->process_single_action( $action );

$this->assertNotEmpty( jet_fb_context()->get_value( 'inserted_page' ) );
$this->assertIsNumeric( jet_fb_context()->get_value( 'inserted_page' ) );

}

public function testComputedNamesOnUpdateWithEmptyPostType() {
$post_id = wp_insert_post(
array(
'post_type' => 'page',
'post_title' => 'something',
'post_content' => '12345',
)
);

$action = new Insert_Post();
$action->_id = 7755;

jet_fb_action_handler()->save_action( $action, array() );

$action->settings = array(
'fields_map' => array(
'_post_id' => 'ID',
),
);


jet_fb_context()->update_request( $post_id, '_post_id' );
jet_fb_action_handler()->process_single_action( $action );

$this->assertNotEmpty( jet_fb_context()->get_value( 'inserted_page' ) );
$this->assertIsNumeric( jet_fb_context()->get_value( 'inserted_page' ) );

}


}

0 comments on commit c1713fc

Please sign in to comment.