Skip to content

Commit

Permalink
Navigation Block: Add missing menu item attributes to core/navigation (
Browse files Browse the repository at this point in the history
…#35634)

* Navigation Block: add target, rel & title attributes

* Nav block: change title to attr_title

* Nav block: add classes attribute

* Nav block: add menu item ID

* Nav block: replace className with classes

* Nav block: add description, kind & type attributes

* Nav block: improve id attribute

* Nav block: remove array to string conversion from navigation-link

* Nav block: change classes to className
  • Loading branch information
mikachan authored Nov 2, 2021
1 parent 154b34a commit 0900c2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 0 additions & 6 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false;

if ( false !== $class_name ) {
$css_classes .= ' ' . $class_name;
}

$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
Expand Down
18 changes: 16 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,25 @@ 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;
$kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom';

$block = array(
'blockName' => 'core/navigation-link',
'attrs' => array(
'label' => $menu_item->title,
'url' => $menu_item->url,
'className' => $class_name,
'description' => $menu_item->description,
'id' => $id,
'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,
),
);

Expand Down

0 comments on commit 0900c2a

Please sign in to comment.