diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 09b06798b59615..0348ec76cfd31d 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -117,6 +117,8 @@ function getSuggestionsQuery( type, kind ) { return { type: 'term', subtype: 'category' }; case 'tag': return { type: 'term', subtype: 'post_tag' }; + case 'post_format': + return { type: 'post-format' }; default: if ( kind === 'taxonomy' ) { return { type: 'term', subtype: type }; diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 5309df8a510270..2720ea870ddcaa 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -233,8 +233,6 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { * @return array */ function build_variation_for_navigation_link( $entity, $kind ) { - $name = 'post_tag' === $entity->name ? 'tag' : $entity->name; - $title = ''; $description = ''; @@ -245,15 +243,45 @@ function build_variation_for_navigation_link( $entity, $kind ) { $description = $entity->labels->item_link_description; } - return array( - 'name' => $name, + $variation = array( + 'name' => $entity->name, 'title' => $title, 'description' => $description, 'attributes' => array( - 'type' => $name, + 'type' => $entity->name, 'kind' => $kind, ), ); + + // Tweak some value for the variations. + $variation_overrides = array( + 'post_tag' => array( + 'name' => 'tag', + 'attributes' => array( + 'type' => 'tag', + 'kind' => $kind, + ), + ), + 'post_format' => array( + // The item_link and item_link_description for post formats is the + // same as for tags, so need to be overridden. + 'title' => __( 'Post Format Link' ), + 'description' => __( 'A link to a post format' ), + 'attributes' => array( + 'type' => 'post_format', + 'kind' => $kind, + ), + ), + ); + + if ( array_key_exists( $entity->name, $variation_overrides ) ) { + $variation = array_merge( + $variation, + $variation_overrides[ $entity->name ] + ); + } + + return $variation; } /** @@ -263,9 +291,13 @@ function build_variation_for_navigation_link( $entity, $kind ) { * @throws WP_Error An WP_Error exception parsing the block definition. */ function register_block_core_navigation_link() { - $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' ); $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' ); + + // Use two separate arrays as a way to order the variations in the UI. + // Known variations (like Post Link and Page Link) are added to the + // `built_ins` array. Variations for custom post types and taxonomies are + // added to the `variations` array and will always appear after `built-ins. $built_ins = array(); $variations = array(); @@ -282,7 +314,7 @@ function register_block_core_navigation_link() { if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { $variation = build_variation_for_navigation_link( $taxonomy, 'taxonomy' ); - if ( 'category' === $variation['name'] || 'tag' === $variation['name'] ) { + if ( 'category' === $variation['name'] || 'tag' === $variation['name'] || 'post_format' === $variation['name'] ) { $built_ins[] = $variation; } else { $variations[] = $variation;