Skip to content

Page List Block: fix warning error when the parent page has no child pages - #46829

Merged
t-hamano merged 1 commit into
trunkfrom
fix/page-list-block-warning
Jan 3, 2023
Merged

t-hamano merged 1 commit into
trunkfrom
fix/page-list-block-warning

Conversation

@t-hamano

@t-hamano t-hamano commented Dec 30, 2022 •

Copy link
Copy Markdown
Contributor

What?

This PR fixes warning error when the parent page has no child pages in te page list block.

Why?

If the parent page that has no child pages is specified, the editor will display a normal alert message in the editor.

warning

However, dynamic rendering treats it as having child pages, resulting in an error that the key does not exist.

Warning: Undefined array key XX in /path/to/wp-content/plugins/gutenberg/build/block-library/blocks/page-list.php on line 312

How?

If the parent page has no child pages, it stops further processing and renders nothing.

Testing Instructions

  • Creates a page that has no child pages.
  • Inset a page list block.
  • Select that page from the block sidebar and save it.
  • Reload the browser and confirm that no PHP errors appear in both the editor and the front end.
  • If a parent page with child pages is selected, confirm that it renders correctly as before.
  • Confirm that it works correctly even when inserted within a navigation block.

@t-hamano t-hamano added the [Block] Page List Affects the Page List Block label Dec 30, 2022
@t-hamano
t-hamano marked this pull request as ready for review December 30, 2022 11:26
@t-hamano t-hamano self-assigned this Dec 30, 2022
@carolinan

Copy link
Copy Markdown
Contributor

I want to ask, should pages without children be selectable as a page list in the first place?
I mean should step 3 in the testing instructions be possible?

@t-hamano

Copy link
Copy Markdown
Contributor Author

should pages without children be selectable as a page list in the first place?

Ideally, only parent pages with child pages would be selectable. But once the block is saved, the child pages of that page may be deleted. I believe this PR is necessary for such cases.

Perhaps the selection of pages should be addressed in a future follow-up.

@carolinan carolinan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a valid point.
I was able to reproduce the issue, and the PR solves it, the PHP notice is no longer present.

@t-hamano
t-hamano merged commit 43c0110 into trunk Jan 3, 2023
@t-hamano
t-hamano deleted the fix/page-list-block-warning branch January 3, 2023 11:48
@github-actions github-actions Bot added this to the Gutenberg 15.0 milestone Jan 3, 2023
@draganescu

Copy link
Copy Markdown
Contributor

Thanks for the work here @t-hamano :) Also @carolinan I think the pages with no children should remain selectable as the menu is dynamic and it could be a default setup situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Page List Affects the Page List Block Needs User Documentation Needs new user documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants