From 5856c9f7e17ad94b756618455ab987467b457b31 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 25 Nov 2021 16:05:36 +0000 Subject: [PATCH 1/2] Move to attr on Page List and remove from Nav block --- packages/block-library/src/navigation/block.json | 6 +----- packages/block-library/src/navigation/index.php | 7 ++++--- packages/block-library/src/page-list/block.json | 9 ++++++--- packages/block-library/src/page-list/index.php | 5 +++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index d4142c2aa67b78..595cd4d755e678 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -55,9 +55,6 @@ }, "customOverlayTextColor": { "type": "string" - }, - "__unstableMaxPages": { - "type": "number" } }, "usesContext": [ "navigationArea" ], @@ -75,8 +72,7 @@ "showSubmenuIcon": "showSubmenuIcon", "openSubmenusOnClick": "openSubmenusOnClick", "style": "style", - "orientation": "orientation", - "__unstableMaxPages": "__unstableMaxPages" + "orientation": "orientation" }, "supports": { "align": [ "wide", "full" ], diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 5e58ff198a7a5a..c4f17bacacbb96 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -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, + ), ), ); @@ -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(); diff --git a/packages/block-library/src/page-list/block.json b/packages/block-library/src/page-list/block.json index ffb8378176fca8..89309cad22b040 100644 --- a/packages/block-library/src/page-list/block.json +++ b/packages/block-library/src/page-list/block.json @@ -7,7 +7,11 @@ "description": "Display a list of all pages.", "keywords": [ "menu", "navigation" ], "textdomain": "default", - "attributes": {}, + "attributes": { + "__unstableMaxPages": { + "type": "number" + } + }, "usesContext": [ "textColor", "customTextColor", @@ -21,8 +25,7 @@ "customFontSize", "showSubmenuIcon", "style", - "openSubmenusOnClick", - "__unstableMaxPages" + "openSubmenusOnClick" ], "supports": { "reusable": false, diff --git a/packages/block-library/src/page-list/index.php b/packages/block-library/src/page-list/index.php index 9a58d06da7274b..ea9613cedc44ea 100644 --- a/packages/block-library/src/page-list/index.php +++ b/packages/block-library/src/page-list/index.php @@ -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 ( array_key_exists( '__unstableMaxPages', $attributes ) ) { + $nested_pages = array_slice( $nested_pages, 0, $attributes['__unstableMaxPages'] ); } $is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context ); From 45c2f55e2a051eb7e1de7dca3330f23165f513b9 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 25 Nov 2021 16:07:05 +0000 Subject: [PATCH 2/2] Use empty check incase attr is falsey but present --- packages/block-library/src/page-list/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/page-list/index.php b/packages/block-library/src/page-list/index.php index ea9613cedc44ea..8336135e1afe0a 100644 --- a/packages/block-library/src/page-list/index.php +++ b/packages/block-library/src/page-list/index.php @@ -294,7 +294,7 @@ function render_block_core_page_list( $attributes, $content, $block ) { $nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children ); // Limit the number of items to be visually displayed. - if ( array_key_exists( '__unstableMaxPages', $attributes ) ) { + if ( ! empty( $attributes['__unstableMaxPages'] ) ) { $nested_pages = array_slice( $nested_pages, 0, $attributes['__unstableMaxPages'] ); }