Skip to content

Commit

Permalink
Page List: Show empty placeholder if no items (#35441)
Browse files Browse the repository at this point in the history
* Add empty response placeholder

* Return early if no top level pages

* Simplify placeholder to just span and text

* Move the check for empty pages up to all_pages

This makes it more clear and bails out even earlier.
  • Loading branch information
mkaz authored Oct 8, 2021
1 parent a969d28 commit 7fcbfdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export default function PageListEdit( {
<ServerSideRender
block="core/page-list"
attributes={ attributesWithParentStatus }
EmptyResponsePlaceholder={ () => (
<span>{ __( 'Page List: No pages to show.' ) }</span>
) }
/>
</div>
</>
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/page-list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ function render_block_core_page_list( $attributes, $content, $block ) {
)
);

// If thare are no pages, there is nothing to show.
// Return early and empty to trigger EmptyResponsePlaceholder.
if ( empty( $all_pages ) ) {
return;
}

$top_level_pages = array();

$pages_with_children = array();
Expand Down

0 comments on commit 7fcbfdb

Please sign in to comment.