Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

[WIP] Add control to manipulate the post parent #189

Closed
wants to merge 9 commits into from
Closed

[WIP] Add control to manipulate the post parent #189

wants to merge 9 commits into from

Conversation

sunnyratilal
Copy link
Contributor

Pull request for #65

@@ -224,6 +224,9 @@
if ( 'undefined' === typeof EditPostPreviewCustomize ) {
section.addPostStatusControl();
}
if ( postTypeObj.supports['page-attributes'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen above with postTypeObj.supports.slug, I suggest we introduce a discrete feature for parent, so this could be:

if ( postTypeObj.supports['page-attributes'] || postTypeObj.supports.parent ) {

@westonruter
Copy link
Contributor

@sunnyratilal this is looking good. I left some feedback.

Something you may want to consider, perhaps in a separate PR, also is adding support for the Object Selector Control, wherein if it is present, the dropdown could be replaced with a select2 field for loading pages on demand.

@westonruter westonruter modified the milestone: 0.8 Aug 6, 2016
@westonruter
Copy link
Contributor

The Customize Object Selector has some new changes that allow it to be used for manipulating the post_parent via passing a setting_property param. This is part of a PR: xwp/wp-customize-object-selector#10

@sunnyratilal
Copy link
Contributor Author

@westonruter will make the amendments soon. Sorry been stuck with university exams in the past few weeks hence I didn't get the chance

@westonruter
Copy link
Contributor

@sunnyratilal no worries! I can pick it up from you if you like.

@westonruter
Copy link
Contributor

westonruter commented Aug 20, 2016

@sunnyratilal here's some code for addPostParentControl for how the Object Selector Control can be used if it is available (again, if xwp/wp-customize-object-selector#10 is merged or the branch is checked out):

var section = this, control, setting = api( section.id ), controlId, params;

controlId = section.id + '[post_parent]';
params = {
    section: section.id,
    priority: 20,
    label: api.Posts.data.l10n.postParentLabel,
    active: true,
    settings: {
        'default': setting.id
    },
    field_type: 'select',
    setting_property: 'post_parent',
    choices: api.Posts.data.postParentChoices
};
if ( api.controlConstructor.object_selector ) {
    control = new api.controlConstructor.object_selector( controlId, {
        params: _.extend( params, {
            post_query_vars: {
                post_type: section.params.post_type,
                post_status: 'publish',
                post__not_in: [ section.params.post_id ]
            },
            select2_options: {
                multiple: false
            }
        } )
    } );
} else {
    control = new api.controlConstructor.dynamic( controlId, {
        params: _.extend( params, {
            field_type: 'select',
            choices: api.Posts.data.postParentChoices
        } )
    } );
}

@westonruter
Copy link
Contributor

(Updated JS snippet to include post__not_in to prevent a page from selecting itself as the parent, and to query all objects of the same post type since non-pages can have post parents as well.)

@westonruter
Copy link
Contributor

Here's what it looks like with the object selector control:

image

@westonruter westonruter changed the title Add control to manipulate the post parent [WIP] Add control to manipulate the post parent Aug 20, 2016
@sunnyratilal
Copy link
Contributor Author

@westonruter I'm going to be really tied up for the next few weeks with other projects so if you'd like to take over, feel free. Sorry for the delay in getting this out.

@westonruter
Copy link
Contributor

No worries. Thanks for the help!

@westonruter
Copy link
Contributor

Picking this up in #233.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants