Skip to content

Commit e95f48d

Browse files
authored
Cleans up the content model CPT (#24)
* adds content_model post type labels * updates dashicon to edit * adds the slug control to inspector controls
1 parent 82fbb6a commit e95f48d

File tree

2 files changed

+119
-66
lines changed

2 files changed

+119
-66
lines changed

includes/manager/class-content-model-loader.php

+33-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,39 @@ private function register_post_type() {
5959
register_post_type(
6060
Content_Model_Manager::POST_TYPE_NAME,
6161
array(
62-
'label' => __( 'Content Models' ),
63-
'public' => true,
64-
'show_in_menu' => true,
65-
'show_in_rest' => true,
66-
'supports' => array( 'title', 'editor', 'custom-fields' ),
62+
'labels' => array(
63+
'name' => __( 'Content Models' ),
64+
'singular_name' => __( 'Content Model' ),
65+
'menu_name' => __( 'Content Models' ),
66+
'all_items' => __( 'All Content Models' ),
67+
'add_new' => __( 'Add New Model' ),
68+
'add_new_item' => __( 'Add New Content Model' ),
69+
'edit_item' => __( 'Edit Content Model' ),
70+
'new_item' => __( 'New Content Model' ),
71+
'view_item' => __( 'View Content Model' ),
72+
'search_items' => __( 'Search Content Models' ),
73+
'not_found' => __( 'No content models found' ),
74+
'not_found_in_trash' => __( 'No content models found in trash' ),
75+
'parent_item_colon' => __( 'Parent Content Model:' ),
76+
'featured_image' => __( 'Featured Image' ),
77+
'set_featured_image' => __( 'Set featured image' ),
78+
'remove_featured_image' => __( 'Remove featured image' ),
79+
'use_featured_image' => __( 'Use as featured image' ),
80+
'archives' => __( 'Content Model archives' ),
81+
'insert_into_item' => __( 'Insert into content model' ),
82+
'uploaded_to_this_item' => __( 'Uploaded to this content model' ),
83+
'filter_items_list' => __( 'Filter content models list' ),
84+
'items_list_navigation' => __( 'Content models list navigation' ),
85+
'items_list' => __( 'Content models list' ),
86+
'attributes' => __( 'Content Model Attributes' ),
87+
),
88+
'public' => true,
89+
'publicly_queryable' => false,
90+
'menu_position' => 60,
91+
'menu_icon' => 'dashicons-edit',
92+
'show_in_menu' => true,
93+
'show_in_rest' => true,
94+
'supports' => array( 'title', 'editor', 'custom-fields' ),
6795
)
6896
);
6997

includes/manager/fields-ui.js

+86-61
Original file line numberDiff line numberDiff line change
@@ -33,77 +33,102 @@ const CreateContentModelPageSettings = function () {
3333
'meta'
3434
);
3535

36+
const [ slug, setSlug ] = useEntityProp(
37+
'postType',
38+
contentModelFields.postType,
39+
'slug'
40+
);
41+
3642
// Saving the fields as serialized JSON because I was tired of fighting the REST API.
3743
const fields = meta?.fields ? JSON.parse( meta.fields ) : [];
3844

3945
return (
40-
<PluginDocumentSettingPanel
41-
name="create-content-model-page-settings"
42-
title={ __( 'Custom Fields' ) }
43-
className="create-content-model-page-settings"
44-
>
45-
<ItemGroup isBordered isSeparated>
46-
{ fields.map( ( field ) => (
47-
<Item key={ field.slug } size="small">
48-
{ field.label }
49-
<code>{ field.slug }</code>
50-
</Item>
51-
) ) }
52-
</ItemGroup>
53-
<div
54-
style={ {
55-
textAlign: 'right',
56-
} }
46+
<>
47+
<PluginDocumentSettingPanel
48+
name="create-content-model-post-settings"
49+
title={ __( 'Post Type' ) }
50+
className="create-content-model-post-settings"
5751
>
58-
<Button
59-
icon={ plus }
60-
onClick={ () => setAddNewOpen( true ) }
61-
label={ __( 'Add Field' ) }
52+
<TextControl
53+
label={ __( 'Slug' ) }
54+
value={ slug }
55+
onChange={ ( value ) => setSlug( value ) }
56+
help={ __(
57+
'Warning: Changing the slug will break existing content.'
58+
) }
59+
/>
60+
</PluginDocumentSettingPanel>
61+
<PluginDocumentSettingPanel
62+
name="create-content-model-field-settings"
63+
title={ __( 'Custom Fields' ) }
64+
className="create-content-model-field-settings"
65+
>
66+
<ItemGroup isBordered isSeparated>
67+
{ fields.map( ( field ) => (
68+
<Item key={ field.slug } size="small">
69+
{ field.label }
70+
<code>{ field.slug }</code>
71+
</Item>
72+
) ) }
73+
</ItemGroup>
74+
<div
6275
style={ {
63-
background: '#1e1e1e',
64-
borderRadius: '2px',
65-
color: '#fff',
66-
height: '24px',
67-
minWidth: '24px',
68-
borderRadius: '0',
76+
textAlign: 'right',
6977
} }
70-
/>
71-
</div>
72-
73-
<Button variant="secondary" onClick={ () => setFieldsOpen( true ) }>
74-
{ __( 'Manage Fields' ) }
75-
</Button>
76-
77-
{ isFieldsOpen && (
78-
<Modal
79-
title={ __( 'Manage Fields' ) }
80-
size="large"
81-
onRequestClose={ () => setFieldsOpen( false ) }
82-
>
83-
<FieldsList />
84-
</Modal>
85-
) }
86-
{ isAddNewOpen && (
87-
<Modal
88-
title={ __( 'Add New Field' ) }
89-
size="large"
90-
onRequestClose={ () => setAddNewOpen( false ) }
9178
>
92-
<EditFieldForm
93-
save={ ( formData ) => {
94-
console.log( 'Save', formData );
95-
setMeta( {
96-
fields: JSON.stringify( [
97-
...fields,
98-
formData,
99-
] ),
100-
} );
101-
setAddNewOpen( false );
79+
<Button
80+
icon={ plus }
81+
onClick={ () => setAddNewOpen( true ) }
82+
label={ __( 'Add Field' ) }
83+
style={ {
84+
background: '#1e1e1e',
85+
borderRadius: '2px',
86+
color: '#fff',
87+
height: '24px',
88+
minWidth: '24px',
89+
borderRadius: '0',
10290
} }
10391
/>
104-
</Modal>
105-
) }
106-
</PluginDocumentSettingPanel>
92+
</div>
93+
94+
<Button
95+
variant="secondary"
96+
onClick={ () => setFieldsOpen( true ) }
97+
>
98+
{ __( 'Manage Fields' ) }
99+
</Button>
100+
101+
{ isFieldsOpen && (
102+
<Modal
103+
title={ __( 'Manage Fields' ) }
104+
size="large"
105+
onRequestClose={ () => setFieldsOpen( false ) }
106+
>
107+
<FieldsList />
108+
</Modal>
109+
) }
110+
{ isAddNewOpen && (
111+
<Modal
112+
title={ __( 'Add New Field' ) }
113+
size="large"
114+
onRequestClose={ () => setAddNewOpen( false ) }
115+
>
116+
<EditFieldForm
117+
save={ ( formData ) => {
118+
console.log( 'Save', formData );
119+
setMeta( {
120+
fields: JSON.stringify( [
121+
...fields,
122+
formData,
123+
] ),
124+
} );
125+
setAddNewOpen( false );
126+
} }
127+
/>
128+
</Modal>
129+
) }
130+
</PluginDocumentSettingPanel>
131+
</>
107132
);
108133
};
109134

0 commit comments

Comments
 (0)