-
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
Terms List block: Add Categories-specific variation #65434
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { category as icon } from '@wordpress/icons'; | ||
|
||
const variations = [ | ||
{ | ||
name: 'terms', | ||
title: __( 'Terms List' ), | ||
icon, | ||
attributes: { | ||
// We need to set an attribute here that will be set when inserting the block. | ||
// We cannot leave this empty, as that would be interpreted as the default value, | ||
// which is `category` -- for which we're defining a distinct variation below, | ||
// for backwards compatibility reasons. | ||
// The logical fallback is thus the only other built-in and public taxonomy: Tags. | ||
taxonomy: 'post_tag', | ||
}, | ||
isActive: ( blockAttributes ) => | ||
// This variation is used for any taxonomy other than `category`. | ||
blockAttributes.taxonomy !== 'category', | ||
}, | ||
{ | ||
name: 'categories', | ||
title: __( 'Categories List' ), | ||
description: __( 'Display a list of all categories.' ), | ||
icon, | ||
attributes: { | ||
taxonomy: 'category', | ||
}, | ||
isActive: [ 'taxonomy' ], | ||
// The following is needed to prevent "Terms List" from showing up twice in the inserter | ||
// (once for the block, once for the variation). Fortunately, it does not collide with | ||
// `categories` being the default value of the `taxonomy` attribute. | ||
isDefault: true, | ||
}, | ||
]; | ||
|
||
export default variations; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you add
isDefault: true
to this variation, then it will resolve the issue with double entries in the inserter. That should make it quite a compelling solution to the problem I like how you handled the Categories vs the rest case.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.
Ah! TIL 😅
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.
Maybe the name for the property should be phrased differently, but the intent is to have a simple way to change the default version of the block in the UI through the variation, instead of using WP filters.
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.
Done in cd379f7 (and 6a8c539).