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.07k stars 264 forks source link

Screen aware context for conditional logic #7113

Open sc0ttkclark opened 1 year ago

sc0ttkclark commented 1 year ago

Problem to Solve

Conditional logic works to reference fields we know information for, these are Pods fields.

We need the ability to reference fields that Pods JS config will provide details about from the current WP screen itself. This contains information about the selector to get the input value from OR what API to use such as the case to get block editor data: wp.data.select( 'core/editor' ).getEditedPostAttribute( 'date' ) ).

Proposed Solution

Screen context provided by the backend could look something like this in window.podsDFVConfig.screenConfig:

{
    "screen": "post-edit",
    "type": "block-editor",
    "availableFields": [
        "post_title": {
            "dataType": "string",
            "source": "wp-core-editor-post-attribute",
            "selector": "title"
        },
        "post_content": {
            "dataType": "string",
            "source": "wp-core-editor-post-attribute",
            "selector": "content"
        },
        "post_status": {
            "dataType": "string",
            "source": "wp-core-editor-post-attribute",
            "selector": "status"
        },
        "some_other_field": {
            "dataType": "string",
            "source": "static",
            "value": "some static value here"
        },
        "some_other_field": {
            "dataType": "array",
            "source": "static",
            "value": [
                "some static value 1 here",
                "some static value 2 here"
            ]
        }
    ]
}

or something like this on the classic editor, note that post_content would have to interact with TinyMCE to get the content:

{
    "screen": "post-edit",
    "type": "classic-editor",
    "availableFields": [
        "post_title": {
            "dataType": "string",
            "source": "input",
            "selector": "#title"
        },
        "post_content": {
            "dataType": "string",
            "source": "wp-tinymce",
            "selector": "content"
        },
        "post_status": {
            "dataType": "string",
            "source": "select",
            "selector": "#post_status"
        }
    ]
}
JoryHogeveen commented 1 year ago

Will this also cover the post's categories/taxonomies, template, status, permalink etc.?