From 6f9c989b56617abd2b50870471c981322d7a679a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 29 Nov 2021 12:42:57 +0100 Subject: [PATCH 1/5] add navigation.menuItemsToBlocks filter to postprocess blocks created from menu items --- packages/block-library/src/navigation/menu-items-to-blocks.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/menu-items-to-blocks.js b/packages/block-library/src/navigation/menu-items-to-blocks.js index b765f38a7ef84..eef93be094dee 100644 --- a/packages/block-library/src/navigation/menu-items-to-blocks.js +++ b/packages/block-library/src/navigation/menu-items-to-blocks.js @@ -7,6 +7,7 @@ import { sortBy } from 'lodash'; * WordPress dependencies */ import { createBlock, parse } from '@wordpress/blocks'; +import { applyFilters } from '@wordpress/hooks'; /** * Convert a flat menu item structure to a nested blocks structure. @@ -21,7 +22,8 @@ export default function menuItemsToBlocks( menuItems ) { } const menuTree = createDataTree( menuItems ); - return mapMenuItemsToBlocks( menuTree ); + const blocks = mapMenuItemsToBlocks( menuTree ); + return applyFilters( 'navigation.menuItemsToBlocks', blocks, menuItems ); } /** From 1b53a2ec96bfe9cb0b9ec538334fda2bd0d2b628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 29 Nov 2021 12:45:36 +0100 Subject: [PATCH 2/5] Add navigation_after_parse_blocks_from_menu_items filter --- lib/navigation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/navigation.php b/lib/navigation.php index 816e2582b8840..f083d85d12587 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -414,7 +414,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $blocks[] = $block; } - return $blocks; + return apply_filters( 'navigation_after_parse_blocks_from_menu_items', $blocks, $menu_items ); } /** From 24e79f50c5d23f710ceebcd5db716096d56f2476 Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Fri, 10 Dec 2021 16:28:00 +0100 Subject: [PATCH 3/5] Make the filter experimental --- packages/block-library/src/navigation/menu-items-to-blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/menu-items-to-blocks.js b/packages/block-library/src/navigation/menu-items-to-blocks.js index cc6f3004b5b75..8284ced9dfa19 100644 --- a/packages/block-library/src/navigation/menu-items-to-blocks.js +++ b/packages/block-library/src/navigation/menu-items-to-blocks.js @@ -23,7 +23,7 @@ export default function menuItemsToBlocks( menuItems ) { const menuTree = createDataTree( menuItems ); const blocks = mapMenuItemsToBlocks( menuTree ); - return applyFilters( 'navigation.menuItemsToBlocks', blocks, menuItems ); + return applyFilters( 'navigation.__experimentalMenuItemsToBlocks', blocks, menuItems ); } /** From 1b63aa38991f652e11035e561bf7223b41d5de29 Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Fri, 10 Dec 2021 16:36:08 +0100 Subject: [PATCH 4/5] Lint --- .../block-library/src/navigation/menu-items-to-blocks.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/menu-items-to-blocks.js b/packages/block-library/src/navigation/menu-items-to-blocks.js index 8284ced9dfa19..ec2a8a995a39b 100644 --- a/packages/block-library/src/navigation/menu-items-to-blocks.js +++ b/packages/block-library/src/navigation/menu-items-to-blocks.js @@ -23,7 +23,11 @@ export default function menuItemsToBlocks( menuItems ) { const menuTree = createDataTree( menuItems ); const blocks = mapMenuItemsToBlocks( menuTree ); - return applyFilters( 'navigation.__experimentalMenuItemsToBlocks', blocks, menuItems ); + return applyFilters( + 'navigation.__experimentalMenuItemsToBlocks', + blocks, + menuItems + ); } /** From 4ffad706e91ea7e61530e1169d89dead6f147def Mon Sep 17 00:00:00 2001 From: Adam Zielinski Date: Fri, 10 Dec 2021 16:39:25 +0100 Subject: [PATCH 5/5] Update menu-items-to-blocks.js --- packages/block-library/src/navigation/menu-items-to-blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/menu-items-to-blocks.js b/packages/block-library/src/navigation/menu-items-to-blocks.js index ec2a8a995a39b..9362f290a572c 100644 --- a/packages/block-library/src/navigation/menu-items-to-blocks.js +++ b/packages/block-library/src/navigation/menu-items-to-blocks.js @@ -24,7 +24,7 @@ export default function menuItemsToBlocks( menuItems ) { const menuTree = createDataTree( menuItems ); const blocks = mapMenuItemsToBlocks( menuTree ); return applyFilters( - 'navigation.__experimentalMenuItemsToBlocks', + 'blocks.navigation.__unstableMenuItemsToBlocks', blocks, menuItems );