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 and noisysocks committed Nov 29, 2021
1 parent 99c9233 commit a72da92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
6 changes: 1 addition & 5 deletions packages/block-library/src/navigation/block.json
Expand Up @@ -58,9 +58,6 @@
},
"customOverlayTextColor": {
"type": "string"
},
"__unstableMaxPages": {
"type": "number"
}
},
"usesContext": [ "navigationArea" ],
Expand All @@ -78,8 +75,7 @@
"showSubmenuIcon": "showSubmenuIcon",
"openSubmenusOnClick": "openSubmenusOnClick",
"style": "style",
"orientation": "orientation",
"__unstableMaxPages": "__unstableMaxPages"
"orientation": "orientation"
},
"supports": {
"align": [
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/navigation/index.php
Expand Up @@ -190,7 +190,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 @@ -308,8 +310,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
3 changes: 1 addition & 2 deletions packages/block-library/src/page-list/block.json
Expand Up @@ -21,8 +21,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'] );
}

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

0 comments on commit a72da92

Please sign in to comment.