Skip to content

Commit

Permalink
Remove unstable max pages attribute from Nav block (#36877)
Browse files Browse the repository at this point in the history
* Move to attr on Page List and remove from Nav block

* Use empty check incase attr is falsey but present
  • Loading branch information
getdave authored Nov 26, 2021
1 parent d7a0066 commit c9e32e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 1 addition & 5 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -314,8 +316,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'] );
}

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

0 comments on commit c9e32e0

Please sign in to comment.