-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation: Add post format variation to navigation link block #30403
Changes from 1 commit
a76b7ce
105b6c9
96533f2
c7de627
a06ff3c
c9d875a
04b3395
256d3e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ import { | |||||||||||||||||||||
page as pageIcon, | ||||||||||||||||||||||
postTitle as postIcon, | ||||||||||||||||||||||
tag as tagIcon, | ||||||||||||||||||||||
blockDefault as formatIcon, | ||||||||||||||||||||||
} from '@wordpress/icons'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// FALLBACK: this is only used when the server does not understand the variations property in the | ||||||||||||||||||||||
|
@@ -49,6 +50,13 @@ const fallbackVariations = [ | |||||||||||||||||||||
description: __( 'A link to a tag.' ), | ||||||||||||||||||||||
attributes: { type: 'tag' }, | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
name: 'format', | ||||||||||||||||||||||
icon: formatIcon, | ||||||||||||||||||||||
title: __( 'Post Format Link' ), | ||||||||||||||||||||||
description: __( 'A link to a post format.' ), | ||||||||||||||||||||||
attributes: { type: 'format' }, | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't seem to make this work without the fallback 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see what's happening. First, I need to be on trunk for core. Now after that I have two Tag Link variations. 😕 Wait, so it looks like Post Formats have the same Someone copied and pasted it years ago and nobody ever noticed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, ok, so I think there are some defaults in core for tags or categories: Seems unusual. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right any WP instances running 5.7 and below will be using the fallback. We'll want to update hooks.js or similar to only add this value when post-formats are supported by the theme: gutenberg/packages/block-library/src/navigation-link/hooks.js Lines 37 to 44 in 836e6db
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant, but I think TT1 does support formats, but the search only shows results when one is added to a published post There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Tempted to either remove it, or keep it as is. The impact is quite low either way. I think I'll remove it for now. |
||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,7 +233,14 @@ 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; | ||
$custom_variation_names = array( | ||
'post_tag' => 'tag', | ||
'post_format' => 'format', | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kind of thing makes me think the variations could be called the same thing as the the entity names. |
||
|
||
$name = array_key_exists( $entity->name, $custom_variation_names ) | ||
? $custom_variation_names[ $entity->name ] | ||
: $entity->name; | ||
|
||
$title = ''; | ||
$description = ''; | ||
|
@@ -263,7 +270,6 @@ 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' ); | ||
$built_ins = array(); | ||
|
@@ -272,7 +278,7 @@ function register_block_core_navigation_link() { | |
if ( $post_types ) { | ||
foreach ( $post_types as $post_type ) { | ||
$variation = build_variation_for_navigation_link( $post_type, 'post-type' ); | ||
if ( 'post' === $variation['name'] || 'page' === $variation['name'] ) { | ||
if ( 'post' === $variation['name'] || 'page' === $variation['name'] || 'format' === $variation['name'] ) { | ||
talldan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$built_ins[] = $variation; | ||
} else { | ||
$variations[] = $variation; | ||
|
@@ -282,7 +288,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_' ) { | ||
$built_ins[] = $variation; | ||
} else { | ||
$variations[] = $variation; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For folks wondering about the kebab case:
gutenberg/packages/editor/src/components/provider/use-block-editor-settings.js
Line 79 in df8e730
FYI on behavior, it also looks like we removed the labels in search results if all results are the same:
#24839
So this is expected behavior: