Skip to content

Commit c5d7a00

Browse files
committed
Editor: Show the placeholder of empty excerpt, description, and author fields.
Turns on the panel layout's `showPlaceholderIfEmpty` option in `view-config.php` for the fields that render nothing when empty, so their row in the editor's summary panel shows the field's placeholder instead of only its label, which gave users no hint the row could be edited until they hovered it: - `excerpt`, in the default post type form and in the `wp_block` form. - `description`, in the `wp_template` form. - `author`, in the default post type form and in the `attachment` form, for a post or media item without a known author, as the post summary did before it moved to the form. DataViews lists are not affected, since the placeholder only shows in the panel summary. Backports the changes from WordPress/gutenberg#85842. Props oandregal, jorgefilipecosta, 0mirka00. Fixes #65981. git-svn-id: https://develop.svn.wordpress.org/trunk@65273 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7516662 commit c5d7a00

2 files changed

Lines changed: 141 additions & 9 deletions

File tree

‎src/wp-includes/view-config.php‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function wp_get_entity_view_config_hook_name( $kind, $name ) {
4545
* returns `false`.
4646
*
4747
* @since 7.1.0
48+
* @since 7.2.0 Shows a placeholder for an empty excerpt and a missing author.
4849
*
4950
* @return array The default form configuration.
5051
*/
@@ -69,8 +70,9 @@ function _wp_get_default_posttype_form() {
6970
array(
7071
'id' => 'excerpt',
7172
'layout' => array(
72-
'type' => 'panel',
73-
'labelPosition' => 'top',
73+
'type' => 'panel',
74+
'labelPosition' => 'top',
75+
'showPlaceholderIfEmpty' => true,
7476
),
7577
),
7678
array(
@@ -95,7 +97,13 @@ function _wp_get_default_posttype_form() {
9597
),
9698
'date',
9799
'slug',
98-
'author',
100+
array(
101+
'id' => 'author',
102+
'layout' => array(
103+
'type' => 'panel',
104+
'showPlaceholderIfEmpty' => true,
105+
),
106+
),
99107
'template',
100108
array(
101109
'id' => 'discussion',
@@ -331,6 +339,7 @@ function _wp_get_entity_view_config_posttype_page( $data ) {
331339
* Provides the view configuration for the `wp_block` post type.
332340
*
333341
* @since 7.1.0
342+
* @since 7.2.0 Shows a placeholder for an empty excerpt.
334343
*
335344
* @param WP_View_Config_Data $data The view configuration container for the entity.
336345
* @return WP_View_Config_Data The updated view configuration container.
@@ -417,8 +426,9 @@ function _wp_get_entity_view_config_posttype_wp_block( $data ) {
417426
array(
418427
'id' => 'excerpt',
419428
'layout' => array(
420-
'type' => 'panel',
421-
'labelPosition' => 'top',
429+
'type' => 'panel',
430+
'labelPosition' => 'top',
431+
'showPlaceholderIfEmpty' => true,
422432
),
423433
),
424434
array(
@@ -552,6 +562,7 @@ function _wp_get_entity_view_config_posttype_wp_template_part( $data ) {
552562
* Provides the view configuration for the `wp_template` post type.
553563
*
554564
* @since 7.1.0
565+
* @since 7.2.0 Shows a placeholder for an empty description.
555566
*
556567
* @param WP_View_Config_Data $data The view configuration container for the entity.
557568
* @return WP_View_Config_Data The updated view configuration container.
@@ -722,8 +733,9 @@ function _wp_get_entity_view_config_posttype_wp_template( $data ) {
722733
array(
723734
'id' => 'description',
724735
'layout' => array(
725-
'type' => 'panel',
726-
'labelPosition' => 'top',
736+
'type' => 'panel',
737+
'labelPosition' => 'top',
738+
'showPlaceholderIfEmpty' => true,
727739
),
728740
),
729741
array(
@@ -813,7 +825,13 @@ function _wp_get_entity_view_config_posttype_attachment( $data ) {
813825
'layout' => $regular_layout,
814826
),
815827
'date',
816-
'author',
828+
array(
829+
'id' => 'author',
830+
'layout' => array(
831+
'type' => 'panel',
832+
'showPlaceholderIfEmpty' => true,
833+
),
834+
),
817835
'filename',
818836
'mime_type',
819837
'filesize',

‎tests/phpunit/tests/view-config.php‎

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,114 @@ public static function data_post_types_with_own_form() {
169169
);
170170
}
171171

172+
/**
173+
* The `excerpt` row shows the field's placeholder when the excerpt is
174+
* empty, for every post type whose form lists the field.
175+
*
176+
* @ticket 65981
177+
*
178+
* @covers ::_wp_get_default_posttype_form
179+
* @covers ::_wp_get_entity_view_config_posttype_wp_block
180+
*
181+
* @dataProvider data_post_types_with_excerpt_in_form
182+
*
183+
* @param string $post_type The post type.
184+
*/
185+
public function test_excerpt_layout_shows_placeholder_if_empty( $post_type ) {
186+
if ( ! post_type_exists( $post_type ) ) {
187+
register_post_type( $post_type );
188+
}
189+
190+
$config = wp_get_entity_view_config( 'postType', $post_type );
191+
192+
$this->assertSame(
193+
array(
194+
'type' => 'panel',
195+
'labelPosition' => 'top',
196+
'showPlaceholderIfEmpty' => true,
197+
),
198+
$this->get_form_field( $config, 'excerpt' )['layout']
199+
);
200+
}
201+
202+
/**
203+
* Data provider.
204+
*
205+
* @return array[]
206+
*/
207+
public function data_post_types_with_excerpt_in_form() {
208+
return array(
209+
'page' => array( 'page' ),
210+
'post' => array( 'post' ),
211+
'wp_block' => array( 'wp_block' ),
212+
'custom post type' => array( 'excerpt_cpt' ),
213+
);
214+
}
215+
216+
/**
217+
* The `description` row of templates shows the field's placeholder when
218+
* the description is empty, like the excerpt of posts and patterns.
219+
*
220+
* @ticket 65981
221+
*
222+
* @covers ::_wp_get_entity_view_config_posttype_wp_template
223+
*/
224+
public function test_wp_template_description_layout_shows_placeholder_if_empty() {
225+
$config = wp_get_entity_view_config( 'postType', 'wp_template' );
226+
227+
$this->assertSame(
228+
array(
229+
'type' => 'panel',
230+
'labelPosition' => 'top',
231+
'showPlaceholderIfEmpty' => true,
232+
),
233+
$this->get_form_field( $config, 'description' )['layout']
234+
);
235+
}
236+
237+
/**
238+
* The `author` row shows the field's placeholder when the post has no
239+
* author, for every post type whose form lists the field.
240+
*
241+
* @ticket 65981
242+
*
243+
* @covers ::_wp_get_default_posttype_form
244+
* @covers ::_wp_get_entity_view_config_posttype_attachment
245+
*
246+
* @dataProvider data_post_types_with_author_in_form
247+
*
248+
* @param string $post_type The post type.
249+
*/
250+
public function test_author_layout_shows_placeholder_if_empty( $post_type ) {
251+
if ( ! post_type_exists( $post_type ) ) {
252+
register_post_type( $post_type );
253+
}
254+
255+
$config = wp_get_entity_view_config( 'postType', $post_type );
256+
257+
$this->assertSame(
258+
array(
259+
'type' => 'panel',
260+
'showPlaceholderIfEmpty' => true,
261+
),
262+
$this->get_form_field( $config, 'author' )['layout']
263+
);
264+
}
265+
266+
/**
267+
* Data provider.
268+
*
269+
* @return array[]
270+
*/
271+
public function data_post_types_with_author_in_form() {
272+
return array(
273+
'page' => array( 'page' ),
274+
'post' => array( 'post' ),
275+
'attachment' => array( 'attachment' ),
276+
'custom post type' => array( 'author_cpt' ),
277+
);
278+
}
279+
172280
/**
173281
* The `attachment` post type provides the form of the media editor: the
174282
* editable fields in a regular layout, then the rest in panels.
@@ -205,7 +313,13 @@ public function test_attachment_form() {
205313
'layout' => $regular_layout,
206314
),
207315
'date',
208-
'author',
316+
array(
317+
'id' => 'author',
318+
'layout' => array(
319+
'type' => 'panel',
320+
'showPlaceholderIfEmpty' => true,
321+
),
322+
),
209323
'filename',
210324
'mime_type',
211325
'filesize',

0 commit comments

Comments
 (0)