-
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 all commits
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 |
---|---|---|
|
@@ -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' ), | ||
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. We can also update the registration here to add the post labels. I didn't realize we wanted to show this one, so I missed it in the last PR. And for folks 👀 changes here, the reason why we added new post labels was because if we combine strings from two translated items, it will generate poor translations. Example from swissspidy:
WP 5.8 is planned for July so I think we can safely make it. (Variation changes aren't present in WP 5.7 and below) It's okay if we miss the date and need a fallback override, but I'd maybe leave a comment on when it can be removed. 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'll push a PR to do that. The thing I was referring to is how the title and description for tag and category are used as fallbacks by core for any taxonomy that doesn't provide certain labels. On trunk I'm seeing two Tag Link variations: The second seems to be post format taxonomy being added as variation but using the title and description of the tag taxonomy (as fallback text). |
||
'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; | ||
|
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: