Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ public static function get_config_schema() {
'type' => 'object',
'additionalProperties' => false,
'properties' => array(
'public' => array( 'type' => 'boolean' ),
'hierarchical' => array( 'type' => 'boolean' ),
'public' => array( 'type' => 'boolean' ),
'hierarchical' => array( 'type' => 'boolean' ),
// Caps payload size; well above any reasonable description.
'description' => array(
'description' => array(
'type' => 'string',
'maxLength' => 1000,
),
'labels' => array(
'publicly_queryable' => array( 'type' => 'boolean' ),
'show_ui' => array( 'type' => 'boolean' ),
'show_in_menu' => array( 'type' => 'boolean' ),
'show_in_nav_menus' => array( 'type' => 'boolean' ),
'show_tagcloud' => array( 'type' => 'boolean' ),
'show_in_quick_edit' => array( 'type' => 'boolean' ),
'show_admin_column' => array( 'type' => 'boolean' ),
'show_in_rest' => array( 'type' => 'boolean' ),
'labels' => array(
'type' => 'object',
'additionalProperties' => false,
'properties' => $label_props,
Expand Down
23 changes: 19 additions & 4 deletions lib/experimental/content-types/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,31 @@ function gutenberg_build_user_taxonomy_args( WP_Post $record ) {
}

$args = array(
'labels' => $labels,
'public' => ! empty( $config['public'] ),
'hierarchical' => ! empty( $config['hierarchical'] ),
'show_in_rest' => true,
'labels' => $labels,
);

if ( ! empty( $config['description'] ) ) {
$args['description'] = (string) $config['description'];
}

$bool_keys = array(
'public',
'hierarchical',
'publicly_queryable',
'show_ui',
'show_in_menu',
'show_in_nav_menus',
'show_tagcloud',
'show_in_quick_edit',
'show_admin_column',
'show_in_rest',
);
foreach ( $bool_keys as $key ) {
if ( array_key_exists( $key, $config ) ) {
$args[ $key ] = (bool) $config[ $key ];
}
}

return array( $slug, $object_type, $args );
}

Expand Down
62 changes: 19 additions & 43 deletions packages/user-taxonomies/src/fields/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Badge, Notice, Stack } from '@wordpress/ui';
*/
import { usePublicPostTypes } from '../utils';
import type { TaxonomyFormData } from '../types';
import { booleanField } from './utils';

export const titleField: Field< TaxonomyFormData > = {
id: 'title',
Expand Down Expand Up @@ -70,35 +71,15 @@ export const descriptionField: Field< TaxonomyFormData > = {
enableSorting: false,
};

export const publicField: Field< TaxonomyFormData > = {
id: 'public',
label: __( 'Public' ),
type: 'boolean',
description: __(
'Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.'
),
getValue: ( { item } ) => item.config.public,
setValue: ( { item, value } ) => ( {
config: { ...item.config, public: !! value },
} ),
filterBy: false,
enableSorting: false,
};

export const hierarchicalField: Field< TaxonomyFormData > = {
id: 'hierarchical',
label: __( 'Hierarchical' ),
type: 'boolean',
description: __(
'When on, terms behave like categories with parent-child relationships. When off, terms behave like tags.'
),
getValue: ( { item } ) => item.config.hierarchical,
setValue: ( { item, value } ) => ( {
config: { ...item.config, hierarchical: !! value },
} ),
filterBy: false,
enableSorting: false,
};
export const hierarchicalField = booleanField(
'hierarchical',
__( 'Hierarchical' ),
{
description: __(
'When on, terms behave like categories with parent-child relationships. When off, terms behave like tags.'
),
}
);

export const statusField: Field< TaxonomyFormData > = {
id: 'status',
Expand Down Expand Up @@ -243,22 +224,17 @@ export const defaultForm: Form = {
'singular_name',
'slug',
'object_type',
'public',
'hierarchical',
'status',
],
};

export const generalForm: Form = {
layout: { type: 'regular' },
fields: [
'plural_name',
'singular_name',
'slug',
'description',
'object_type',
'public',
'hierarchical',
'status',
],
};
export const generalFormFields: Form[ 'fields' ] = [
'plural_name',
'singular_name',
'slug',
'object_type',
'description',
'hierarchical',
'status',
];
1 change: 1 addition & 0 deletions packages/user-taxonomies/src/fields/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './general';
export * from './labels';
export * from './visibility';
17 changes: 7 additions & 10 deletions packages/user-taxonomies/src/fields/labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,11 @@ export const labelsActionsField: Field< TaxonomyFormData > = {
filterBy: false,
};

export const labelsForm: Form = {
layout: { type: 'regular' },
export const labelsFormFields: Form[ 'fields' ] = [
{
id: '__labels_actions',
layout: { type: 'regular', labelPosition: 'none' },
},
// singular_name lives in the General card, so exclude it here.
fields: [
{
id: '__labels_actions',
layout: { type: 'regular', labelPosition: 'none' },
},
...STRING_LABEL_KEYS.filter( ( key ) => key !== 'singular_name' ),
],
};
...STRING_LABEL_KEYS.filter( ( key ) => key !== 'singular_name' ),
];
50 changes: 50 additions & 0 deletions packages/user-taxonomies/src/fields/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* WordPress dependencies
*/
import type { Field } from '@wordpress/dataviews';

/**
* Internal dependencies
*/
import type { TaxonomyFormData } from '../types';

type BooleanConfigKey =
| 'public'
| 'hierarchical'
| 'publicly_queryable'
| 'show_ui'
| 'show_in_menu'
| 'show_in_nav_menus'
| 'show_tagcloud'
| 'show_in_quick_edit'
| 'show_admin_column'
| 'show_in_rest';

type BooleanOptions = {
description: string;
isVisible?: ( item: TaxonomyFormData ) => boolean;
};

export function booleanField(
id: BooleanConfigKey,
label: string,
options: BooleanOptions
): Field< TaxonomyFormData > {
const field: Field< TaxonomyFormData > = {
id,
label,
type: 'boolean',
description: options.description,
Edit: 'toggle',
getValue: ( { item } ) => item.config[ id ],
setValue: ( { item, value } ) => ( {
config: { ...item.config, [ id ]: !! value },
} ),
filterBy: false,
enableSorting: false,
};
if ( options.isVisible ) {
field.isVisible = options.isVisible;
}
return field;
}
108 changes: 108 additions & 0 deletions packages/user-taxonomies/src/fields/visibility.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* WordPress dependencies
*/
import type { Form } from '@wordpress/dataviews';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { booleanField } from './utils';

export const publicField = booleanField( 'public', __( 'Public' ), {
description: __(
'Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.'
),
} );

export const showInRestField = booleanField(
'show_in_rest',
__( 'Show in REST API' ),
{
description: __(
'Required for the block editor. Turn off only for taxonomies that should not be exposed via REST.'
),
}
);

export const publiclyQueryableField = booleanField(
'publicly_queryable',
__( 'Publicly queryable' ),
{
description: __(
'Whether front-end queries (e.g. ?taxonomy=…&term=…) can return terms from this taxonomy.'
),
}
);

export const showUiField = booleanField( 'show_ui', __( 'Show admin UI' ), {
description: __(
'Whether to generate a default admin interface for managing terms.'
),
} );

export const showInMenuField = booleanField(
'show_in_menu',
__( 'Show in admin menu' ),
{
description: __(
'Whether to show the taxonomy in the admin menu. Has no effect when Show admin UI is off; the value is preserved either way.'
),
// Hide when `show_ui` is off — `show_in_menu` is silently ignored by
// register_taxonomy() in that case, so showing the toggle would be
// misleading. The stored value is preserved across the toggle.
isVisible: ( item ) => item.config.show_ui,
}
);

export const showInQuickEditField = booleanField(
'show_in_quick_edit',
__( 'Show in Quick Edit' ),
{
description: __(
'Whether to show the taxonomy in the Quick/Bulk Edit panel.'
),
}
);

export const showAdminColumnField = booleanField(
'show_admin_column',
__( 'Show admin column' ),
{
description: __(
'Whether to display a column for the taxonomy on the associated post type list tables.'
),
}
);

export const showInNavMenusField = booleanField(
'show_in_nav_menus',
__( 'Available in nav menus' ),
{
description: __(
'Whether terms are selectable in the theme nav menu builder.'
),
}
);

export const showTagcloudField = booleanField(
'show_tagcloud',
__( 'Available in Tag Cloud widget' ),
{
description: __(
'Whether terms can be displayed in the Tag Cloud widget.'
),
}
);

export const visibilityFormFields: Form[ 'fields' ] = [
'public',
'show_in_rest',
'publicly_queryable',
'show_ui',
'show_in_menu',
'show_in_quick_edit',
'show_in_nav_menus',
'show_tagcloud',
'show_admin_column',
];
20 changes: 18 additions & 2 deletions packages/user-taxonomies/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ export interface StoredLabels {
export interface StoredConfig {
labels?: StoredLabels;
description?: string;
public?: boolean;
hierarchical?: boolean;
public: boolean;
hierarchical: boolean;
publicly_queryable: boolean;
show_ui: boolean;
show_in_menu: boolean;
show_in_nav_menus: boolean;
show_tagcloud: boolean;
show_in_quick_edit: boolean;
show_admin_column: boolean;
show_in_rest: boolean;
}

/**
Expand All @@ -54,6 +62,14 @@ export interface TaxonomyFormData {
description: string;
public: boolean;
hierarchical: boolean;
publicly_queryable: boolean;
show_ui: boolean;
show_in_menu: boolean;
show_in_nav_menus: boolean;
show_tagcloud: boolean;
show_in_quick_edit: boolean;
show_admin_column: boolean;
show_in_rest: boolean;
};
}

Expand Down
Loading
Loading