From 08a06017c4b035367de187644104a208f9d00ba3 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Thu, 14 Oct 2021 10:55:35 +0100 Subject: [PATCH 1/9] Navigation Block: add target, rel & title attributes --- packages/block-library/src/navigation/index.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 32c3fbea0ef46..ba0d7ae9951a1 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -161,11 +161,17 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $blocks = array(); foreach ( $menu_items as $menu_item ) { + $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; + $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; + $block = array( 'blockName' => 'core/navigation-link', 'attrs' => array( - 'label' => $menu_item->title, - 'url' => $menu_item->url, + 'label' => $menu_item->title, + 'opensInNewTab' => $opens_in_new_tab, + 'rel' => $rel, + 'title' => $menu_item->title, + 'url' => $menu_item->url, ), ); From dae69cf939935caf712b6654de42a0d2b0e8b119 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 15 Oct 2021 16:37:55 +0100 Subject: [PATCH 2/9] Nav block: change title to attr_title --- packages/block-library/src/navigation/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index ba0d7ae9951a1..de37165901ddb 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -170,7 +170,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, - 'title' => $menu_item->title, + 'title' => $menu_item->attr_title, 'url' => $menu_item->url, ), ); From 00ec38e7285886b21152e939b71e48e24073a8f1 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 15 Oct 2021 17:25:32 +0100 Subject: [PATCH 3/9] Nav block: add classes attribute --- packages/block-library/src/navigation-link/index.php | 7 ++++++- packages/block-library/src/navigation/index.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 9839d878363ac..610d8a2cfb248 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -152,12 +152,17 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { $has_submenu = count( $block->inner_blocks ) > 0; $is_active = ! empty( $attributes['id'] ) && ( get_the_ID() === $attributes['id'] ); - $class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false; + $class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false; + $custom_classes = ! empty( $attributes['classes'] ) ? implode( ' ', (array) $attributes['classes'] ) : false; if ( false !== $class_name ) { $css_classes .= ' ' . $class_name; } + if ( false !== $custom_classes ) { + $css_classes .= ' ' . $custom_classes; + } + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index de37165901ddb..73d7fe0371588 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -167,6 +167,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $block = array( 'blockName' => 'core/navigation-link', 'attrs' => array( + 'classes' => $menu_item->classes, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, From d006b41251eaffb19e881fd28dc9099b7fcdb3e1 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 20 Oct 2021 09:58:30 +0100 Subject: [PATCH 4/9] Nav block: add menu item ID --- packages/block-library/src/navigation/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 73d7fe0371588..5a6935695ee2b 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -168,6 +168,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par 'blockName' => 'core/navigation-link', 'attrs' => array( 'classes' => $menu_item->classes, + 'id' => $menu_item->object_id, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, From 691c15a7eaa4979cb5ea360d9a5a65213ff2474a Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 20 Oct 2021 18:23:29 +0100 Subject: [PATCH 5/9] Nav block: replace className with classes --- packages/block-library/src/navigation-link/index.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 610d8a2cfb248..1570e1e40532b 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -152,15 +152,10 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { $has_submenu = count( $block->inner_blocks ) > 0; $is_active = ! empty( $attributes['id'] ) && ( get_the_ID() === $attributes['id'] ); - $class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false; - $custom_classes = ! empty( $attributes['classes'] ) ? implode( ' ', (array) $attributes['classes'] ) : false; + $class_names = ! empty( $attributes['classes'] ) ? implode( ' ', (array) $attributes['classes'] ) : false; - if ( false !== $class_name ) { - $css_classes .= ' ' . $class_name; - } - - if ( false !== $custom_classes ) { - $css_classes .= ' ' . $custom_classes; + if ( false !== $class_names ) { + $css_classes .= ' ' . $class_names; } $wrapper_attributes = get_block_wrapper_attributes( From e0d8ae5a0a228d1d7424c51e44e60045037f2e8f Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 20 Oct 2021 18:29:37 +0100 Subject: [PATCH 6/9] Nav block: add description, kind & type attributes --- packages/block-library/src/navigation/index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 5a6935695ee2b..fd1565547eb6e 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -163,16 +163,20 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par foreach ( $menu_items as $menu_item ) { $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; + $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; $block = array( 'blockName' => 'core/navigation-link', 'attrs' => array( 'classes' => $menu_item->classes, 'id' => $menu_item->object_id, + 'description' => $menu_item->description, + 'kind' => $kind, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, 'rel' => $rel, 'title' => $menu_item->attr_title, + 'type' => $menu_item->object, 'url' => $menu_item->url, ), ); From 10181ceaa052e072f5924662eb0c8fee1856d147 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Wed, 20 Oct 2021 18:30:19 +0100 Subject: [PATCH 7/9] Nav block: improve id attribute --- packages/block-library/src/navigation/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index fd1565547eb6e..38ea3e5930e68 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -161,6 +161,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $blocks = array(); foreach ( $menu_items as $menu_item ) { + $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null; $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; @@ -169,8 +170,8 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par 'blockName' => 'core/navigation-link', 'attrs' => array( 'classes' => $menu_item->classes, - 'id' => $menu_item->object_id, 'description' => $menu_item->description, + 'id' => $id, 'kind' => $kind, 'label' => $menu_item->title, 'opensInNewTab' => $opens_in_new_tab, From 376f0710faa0197748c640fb351f34628262ae7d Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 22 Oct 2021 12:55:31 +0100 Subject: [PATCH 8/9] Nav block: remove array to string conversion from navigation-link --- packages/block-library/src/navigation-link/index.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 1570e1e40532b..a038bc8f400e1 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -152,12 +152,6 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { $has_submenu = count( $block->inner_blocks ) > 0; $is_active = ! empty( $attributes['id'] ) && ( get_the_ID() === $attributes['id'] ); - $class_names = ! empty( $attributes['classes'] ) ? implode( ' ', (array) $attributes['classes'] ) : false; - - if ( false !== $class_names ) { - $css_classes .= ' ' . $class_names; - } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . From 198297de5a56ef71e17938a60d05ae0beed486de Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 22 Oct 2021 12:57:27 +0100 Subject: [PATCH 9/9] Nav block: change classes to className --- packages/block-library/src/navigation/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 38ea3e5930e68..69716892e792c 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -161,6 +161,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $blocks = array(); foreach ( $menu_items as $menu_item ) { + $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null; $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null; $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; @@ -169,7 +170,7 @@ function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_par $block = array( 'blockName' => 'core/navigation-link', 'attrs' => array( - 'classes' => $menu_item->classes, + 'className' => $class_name, 'description' => $menu_item->description, 'id' => $id, 'kind' => $kind,