File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * External dependencies
3+ */
4+ import type { ReactElement } from 'react' ;
5+
16/**
27 * Internal dependencies
38 */
@@ -143,15 +148,15 @@ export type NormalizedSummaryField =
143148export type FormField = {
144149 id : string ;
145150 label ?: string ;
146- description ?: string ;
151+ description ?: string | ReactElement ;
147152 layout ?: Layout ;
148153 children ?: Array < FormField | string > ;
149154} ;
150155export type NormalizedFormField = {
151156 id : string ;
152157 layout : NormalizedLayout ;
153158 label ?: string ;
154- description ?: string ;
159+ description ?: string | ReactElement ;
155160 children ?: NormalizedFormField [ ] ;
156161} ;
157162
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ export type Field< Item > = {
200200 /**
201201 * A description of the field.
202202 */
203- description ?: string ;
203+ description ?: string | ReactElement ;
204204
205205 /**
206206 * Placeholder for the field.
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ const form = {
3838 labelPosition : 'none' ,
3939 } ,
4040 } ,
41+ 'excerpt' ,
4142 {
4243 id : 'status' ,
4344 label : __ ( 'Status' ) ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 resetPost ,
2020 deletePost ,
2121 duplicateTemplatePart ,
22+ excerptField ,
2223 featuredImageField ,
2324 dateField ,
2425 parentField ,
@@ -267,6 +268,11 @@ export const registerPostTypeSchema =
267268 ! DESIGN_POST_TYPES . includes ( postTypeConfig . slug ) &&
268269 scheduledDateField ,
269270 slugField ,
271+ // There are special cases where we want to label the excerpt as a description.
272+ // So for now skip registering the excerpt field for some post types.
273+ ! DESIGN_POST_TYPES . includes ( postTypeConfig . slug ) &&
274+ postTypeConfig . supports ?. excerpt &&
275+ excerptField ,
270276 postTypeConfig . supports ?. [ 'page-attributes' ] && parentField ,
271277 postTypeConfig . supports ?. comments && commentStatusField ,
272278 postTypeConfig . supports ?. trackbacks && pingStatusField ,
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ Duplicate action for BasePost.
6363
6464Duplicate action for TemplatePart.
6565
66+ ### excerptField
67+
68+ Excerpt field for BasePost.
69+
6670### exportPattern
6771
6872Export action as JSON for Pattern.
Original file line number Diff line number Diff line change 1+ /**
2+ * WordPress dependencies
3+ */
4+ import type { Field } from '@wordpress/dataviews' ;
5+ import { decodeEntities } from '@wordpress/html-entities' ;
6+ import { __ } from '@wordpress/i18n' ;
7+ import {
8+ ExternalLink ,
9+ __experimentalText as Text ,
10+ } from '@wordpress/components' ;
11+
12+ /**
13+ * Internal dependencies
14+ */
15+ import type { BasePost } from '../../types' ;
16+
17+ const excerptField : Field < BasePost > = {
18+ id : 'excerpt' ,
19+ type : 'text' ,
20+ label : __ ( 'Excerpt' ) ,
21+ placeholder : __ ( 'Add an excerpt' ) ,
22+ description : (
23+ < ExternalLink
24+ href = { __ (
25+ 'https://wordpress.org/documentation/article/page-post-settings-sidebar/#excerpt'
26+ ) }
27+ >
28+ { __ ( 'Learn more about manual excerpts' ) }
29+ </ ExternalLink >
30+ ) ,
31+ render : ( { item } ) => {
32+ let excerpt ;
33+ if ( typeof item . excerpt === 'string' ) {
34+ excerpt = ! ! item . excerpt
35+ ? decodeEntities ( item . excerpt )
36+ : __ ( 'Add an excerpt' ) ;
37+ } else {
38+ excerpt = decodeEntities ( item . excerpt ?. raw || '' ) ;
39+ }
40+ return (
41+ < Text align = "left" numberOfLines = { 4 } truncate >
42+ { excerpt }
43+ </ Text >
44+ ) ;
45+ } ,
46+ Edit : {
47+ control : 'textarea' ,
48+ rows : 4 ,
49+ } ,
50+ enableSorting : false ,
51+ filterBy : false ,
52+ } ;
53+
54+ /**
55+ * Excerpt field for BasePost.
56+ */
57+ export default excerptField ;
Original file line number Diff line number Diff line change @@ -16,5 +16,6 @@ export { default as dateField } from './date';
1616export { default as scheduledDateField } from './date/scheduled' ;
1717export { default as authorField } from './author' ;
1818export { default as notesField } from './notes' ;
19+ export { default as excerptField } from './excerpt' ;
1920export { default as formatField } from './format' ;
2021export { default as postContentInfoField } from './post-content-info' ;
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ export interface PostType {
127127 supports ?: {
128128 'page-attributes' ?: boolean ;
129129 title ?: boolean ;
130+ excerpt ?: boolean ;
130131 revisions ?: boolean ;
131132 author ?: string ;
132133 thumbnail ?: string ;
You can’t perform that action at this time.
0 commit comments