pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.06k stars 265 forks source link

Pods blocks feature (pods_register_block_type) doesn't work with configs from 'get_args()' #7274

Closed WPLake closed 3 months ago

WPLake commented 3 months ago

Description

How to replicate the issue:

  1. Register a new Pods block using the 'pods_register_block_type' function and include field types distinct from text (e.g., date or select). For field settings, use field configs of existing fields obtained from the API
  2. Add the block to some page.
  3. Try to fill out the fields

Current behavior:

Field types other than text are not present in the registered block.

Expected behavior:

All fields passed to the signup function should be present in the block.

Details:

The documentation (https://docs.pods.io/code/blocks-api/) states that "fields in pods_register_block_type() use the same exact field config form as normal Pod fields," and it does not mention any field type restrictions.


1. Getting settings of the existing field

$args = pods_api()->load_field(
            array(
                'pod'  => 'x',
                'name' => 'y',
            )
        )->get_args();
        $args = array_diff_key(
            $args,
            array(
                'object_type'         => '',
                'object_storage_type' => '',
                'id'                  => '',
                'parent'              => '',
                'group'               => '',
                'sister_id'           => '',
            )
        );

2. Signing up the block

Array
(
    [namespace] => my-namespace
    [name] => my-name-123
    [title] => tmp
    [description] =>  My description.
    [category] => My category
    [render_type] => php
)

3. Passing the field configs

Array
(
    [0] => Array
        (
            [name] => text
            [label] => Text
            [description] => 
            [weight] => 0
            [type] => text
            [required] => 0
            [text_allowed_html_tags] => strong em a ul ol li b i
            [text_max_length] => 255
            [repeatable] => 0
            [repeatable_format] => default
            [roles_allowed] => administrator
            [enable_conditional_logic] => 0
            [rest_pick_response] => array
            [rest_pick_depth] => 1
        )

    [1] => Array
        (
            [name] => date_field
            [label] => Date field
            [description] => 
            [weight] => 1
            [type] => date
            [required] => 0
            [date_type] => wp
            [date_format] => mdy
            [date_allow_empty] => 1
            [date_html5] => 0
            [repeatable] => 0
            [repeatable_format] => default
            [roles_allowed] => administrator
            [enable_conditional_logic] => 0
            [rest_pick_response] => array
            [rest_pick_depth] => 1
        )

    [2] => Array
        (
            [name] => select_single
            [label] => Select single
            [description] => 
            [weight] => 4
            [type] => pick
            [pick_object] => custom-simple
            [pick_table] => -- Select One --
            [required] => 0
            [pick_format_type] => single
            [pick_format_single] => dropdown
            [pick_format_multi] => list
            [pick_display_format_multi] => default
            [pick_display_format_separator] => , 
            [pick_allow_add_new] => 1
            [pick_taggable] => 0
            [pick_show_icon] => 1
            [pick_show_edit_link] => 1
            [pick_show_view_link] => 1
            [pick_limit] => 0
            [pick_user_role] => Administrator
            [pick_post_status] => publish
            [pick_post_author] => 0
            [repeatable] => 0
            [repeatable_format] => default
            [roles_allowed] => administrator
            [enable_conditional_logic] => 0
            [rest_pick_response] => array
            [rest_pick_depth] => 1
            [pick_custom] => first|First
second|Second
third|Third
            [old_name] => select
        )

)```

### Version

3.1.4
sc0ttkclark commented 3 months ago

Currently only these field types are supported:

The reason for the reduced support here is that this was originally developed before we had all of our field types converted for React. As a result, these field types are mapped to the supported field types in Gutenberg at the time.

If we get a good React developer helping on the project again, we can consolidate the form fields handling in our Blocks API to completely map over to our Pods DFV API which powers our normal forms (these are different React APIs at the moment).

WPLake commented 3 months ago

@sc0ttkclark Thank you for the clarification. I hope that the upcoming improvement to the WP Blocks API in version 6.5 is just the beginning, and eventually, we'll have a fully developed API.