From 91dc798ec1728342d4b2f55936c67b456eb5f952 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Fri, 10 Dec 2021 15:32:36 -0500 Subject: [PATCH 1/3] Add menu-item-home class to Navigation for front page Closes #29423 --- packages/block-library/src/page-list/index.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/block-library/src/page-list/index.php b/packages/block-library/src/page-list/index.php index 3ecedaa5e23da..bbdff17d8ef45 100644 --- a/packages/block-library/src/page-list/index.php +++ b/packages/block-library/src/page-list/index.php @@ -173,6 +173,11 @@ function block_core_page_list_render_nested_page_list( $open_submenus_on_click, } } + $front_page_id = (int) get_option( 'page_on_front' ); + if ( (int) $page['page_id'] === $front_page_id ) { + $css_class .= ' menu-item-home'; + } + $title = wp_kses( $page['title'], wp_kses_allowed_html( 'post' ) ); $aria_label = sprintf( /* translators: Accessibility text. %s: Parent page title. */ From 7d314918e15c10443df10d794a2805d84920e3af Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Thu, 16 Dec 2021 11:48:17 -0500 Subject: [PATCH 2/3] Fixing front-end classes --- packages/block-library/src/page-list/edit.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/page-list/edit.js b/packages/block-library/src/page-list/edit.js index 0818fe0b0446e..f46d302cc4c91 100644 --- a/packages/block-library/src/page-list/edit.js +++ b/packages/block-library/src/page-list/edit.js @@ -29,7 +29,7 @@ import { ItemSubmenuIcon } from '../navigation-link/icons'; const MAX_PAGE_COUNT = 100; export default function PageListEdit( { context, clientId } ) { - const { pagesByParentId, totalPages } = usePagesByParentId(); + const { pagesByParentId, totalPages } = usePageData(); const isNavigationChild = 'showSubmenuIcon' in context; const allowConvertToLinks = @@ -94,7 +94,14 @@ export default function PageListEdit( { context, clientId } ) { ); } -function usePagesByParentId() { +function useFrontPageId() { + return useSelect( ( select ) => { + const site = select( coreStore ).getEntityRecord( 'site', 'root' ); + return site?.show_on_front === 'page' && site?.page_on_front + }, [] ); +} + +function usePageData() { const { pages } = useSelect( ( select ) => { const { getEntityRecords } = select( coreStore ); @@ -137,6 +144,7 @@ const PageItems = memo( function PageItems( { depth = 0, } ) { const pages = pagesByParentId.get( parentId ); + const frontPageId = useFrontPageId(); if ( ! pages?.length ) { return []; @@ -155,6 +163,7 @@ const PageItems = memo( function PageItems( { 'open-on-hover-click': ! context.openSubmenusOnClick && context.showSubmenuIcon, + 'menu-item-home': page.id === frontPageId } ) } > { hasChildren && context.openSubmenusOnClick ? ( From 6d0f12c8d9c30b1a81446c41b6df3c544511c6fa Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Fri, 17 Dec 2021 11:40:44 -0500 Subject: [PATCH 3/3] Whoops, had the args in the wrong order --- packages/block-library/src/page-list/edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/page-list/edit.js b/packages/block-library/src/page-list/edit.js index f46d302cc4c91..f6f3b2c033bd9 100644 --- a/packages/block-library/src/page-list/edit.js +++ b/packages/block-library/src/page-list/edit.js @@ -96,8 +96,8 @@ export default function PageListEdit( { context, clientId } ) { function useFrontPageId() { return useSelect( ( select ) => { - const site = select( coreStore ).getEntityRecord( 'site', 'root' ); - return site?.show_on_front === 'page' && site?.page_on_front + const site = select( coreStore ).getEntityRecord( 'root', 'site' ); + return site?.show_on_front === 'page' && site?.page_on_front; }, [] ); } @@ -163,7 +163,7 @@ const PageItems = memo( function PageItems( { 'open-on-hover-click': ! context.openSubmenusOnClick && context.showSubmenuIcon, - 'menu-item-home': page.id === frontPageId + 'menu-item-home': page.id === frontPageId, } ) } > { hasChildren && context.openSubmenusOnClick ? (