Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unstable max pages attribute from Nav block #36877

Merged
merged 2 commits into from Nov 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/block-library/src/navigation/block.json
Expand Up @@ -55,9 +55,6 @@
},
"customOverlayTextColor": {
"type": "string"
},
"__unstableMaxPages": {
"type": "number"
}
},
"usesContext": [ "navigationArea" ],
Expand All @@ -75,8 +72,7 @@
"showSubmenuIcon": "showSubmenuIcon",
"openSubmenusOnClick": "openSubmenusOnClick",
"style": "style",
"orientation": "orientation",
"__unstableMaxPages": "__unstableMaxPages"
"orientation": "orientation"
},
"supports": {
"align": [ "wide", "full" ],
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/navigation/index.php
Expand Up @@ -192,7 +192,9 @@ function block_core_navigation_get_fallback_blocks() {
$page_list_fallback = array(
array(
'blockName' => 'core/page-list',
'attrs' => array(),
'attrs' => array(
'__unstableMaxPages' => 4,
),
),
);

Expand Down Expand Up @@ -305,8 +307,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {

// If there are no inner blocks then fallback to rendering an appropriate fallback.
if ( empty( $inner_blocks ) ) {
$is_fallback = true; // indicate we are rendering the fallback.
$attributes['__unstableMaxPages'] = 4; // set value to be passed as context to Page List block.
$is_fallback = true; // indicate we are rendering the fallback.

$fallback_blocks = block_core_navigation_get_fallback_blocks();

Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/page-list/block.json
Expand Up @@ -7,7 +7,11 @@
"description": "Display a list of all pages.",
"keywords": [ "menu", "navigation" ],
"textdomain": "default",
"attributes": {},
"attributes": {
"__unstableMaxPages": {
"type": "number"
}
},
"usesContext": [
"textColor",
"customTextColor",
Expand All @@ -21,8 +25,7 @@
"customFontSize",
"showSubmenuIcon",
"style",
"openSubmenusOnClick",
"__unstableMaxPages"
"openSubmenusOnClick"
],
"supports": {
"reusable": false,
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/page-list/index.php
Expand Up @@ -293,8 +293,9 @@ function render_block_core_page_list( $attributes, $content, $block ) {

$nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children );

if ( array_key_exists( '__unstableMaxPages', $block->context ) ) {
$nested_pages = array_slice( $nested_pages, 0, $block->context['__unstableMaxPages'] );
// Limit the number of items to be visually displayed.
if ( ! empty( $attributes['__unstableMaxPages'] ) ) {
$nested_pages = array_slice( $nested_pages, 0, $attributes['__unstableMaxPages'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it should be an argument to get_pages, usually that supports adding a limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Let's consider a followup.

}

$is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context );
Expand Down