-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add more taxonomy options to the post navigation link #48912
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2c86378
Add 3 options to the post navigation link
carolinan aefb961
Update core__post-navigation-link.json
carolinan ec7dc9d
Support custom post types and custom taxonomies
carolinan 393afa8
fix CS issues
carolinan 3341d55
Update index.php
carolinan 7836c63
Update index.php
carolinan 1a11e8a
Update edit.js
carolinan 8976803
Merge branch 'trunk' into update/post-navigation-link
carolinan de19789
Merge branch 'trunk' into update/post-navigation-link
carolinan 449a40a
try to fix spacing in core-blocks.md
carolinan c40a61d
Merge branch 'trunk' into update/post-navigation-link
carolinan 156bde0
Merge branch 'trunk' into update/post-navigation-link
carolinan d5cd379
Remove the taxonomy filter toggle and update the PHP conditions.
carolinan 9279206
Update core__post-navigation-link.json
carolinan 5ae72a6
Merge branch 'trunk' into update/post-navigation-link
carolinan 9e215f0
Update help text about excluding terms
carolinan 80f5a95
Update help text again.
carolinan a39c201
Merge branch 'trunk' into update/post-navigation-link
carolinan 074518f
Merge branch 'trunk' into update/post-navigation-link
carolinan 969aeaf
Merge branch 'trunk' into update/post-navigation-link
carolinan 4c40be4
Merge branch 'trunk' into update/post-navigation-link
carolinan f2ac603
Merge branch 'trunk' into update/post-navigation-link
carolinan bf28bda
Remove the exclude terms feature, move filter to advanced panel
carolinan a0f1da9
Try to fix CS issues
carolinan 6f73362
Update docs
carolinan c94aecb
Try to fix CS issues
carolinan 54a58bb
Use context to get the postType
carolinan b2106f9
Merge branch 'trunk' into update/post-navigation-link
carolinan 9c14221
Merge branch 'trunk' into update/post-navigation-link
carolinan 261926a
Merge branch 'trunk' into update/post-navigation-link
carolinan 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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
ToggleControl, | ||
SelectControl, | ||
PanelBody, | ||
} from '@wordpress/components'; | ||
import { | ||
|
@@ -20,9 +21,20 @@ import { | |
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
export default function PostNavigationLinkEdit( { | ||
attributes: { type, label, showTitle, textAlign, linkLabel, arrow }, | ||
context: { postType }, | ||
attributes: { | ||
type, | ||
label, | ||
showTitle, | ||
textAlign, | ||
linkLabel, | ||
arrow, | ||
taxonomy, | ||
}, | ||
setAttributes, | ||
} ) { | ||
const isNext = type === 'next'; | ||
|
@@ -47,6 +59,40 @@ export default function PostNavigationLinkEdit( { | |
[ `has-text-align-${ textAlign }` ]: textAlign, | ||
} ), | ||
} ); | ||
|
||
const taxonomies = useSelect( | ||
( select ) => { | ||
const { getTaxonomies } = select( coreStore ); | ||
const filteredTaxonomies = getTaxonomies( { | ||
type: postType, | ||
per_page: -1, | ||
context: 'view', | ||
} ); | ||
return filteredTaxonomies; | ||
}, | ||
[ postType ] | ||
); | ||
const getTaxonomyOptions = () => { | ||
const selectOption = { | ||
label: __( 'Unfiltered' ), | ||
value: '', | ||
}; | ||
const taxonomyOptions = ( taxonomies ?? [] ) | ||
.filter( | ||
( tax ) => | ||
tax.slug !== 'nav_menu' && | ||
tax.slug !== 'wp_pattern_category' | ||
) | ||
.map( ( item ) => { | ||
return { | ||
value: item.slug, | ||
label: item.name, | ||
}; | ||
} ); | ||
|
||
return [ selectOption, ...taxonomyOptions ]; | ||
}; | ||
|
||
return ( | ||
<> | ||
<InspectorControls> | ||
|
@@ -114,6 +160,22 @@ export default function PostNavigationLinkEdit( { | |
</ToggleGroupControl> | ||
</PanelBody> | ||
</InspectorControls> | ||
<InspectorControls group="advanced"> | ||
<SelectControl | ||
label={ __( 'Filter by taxonomy' ) } | ||
value={ taxonomy } | ||
options={ getTaxonomyOptions() } | ||
onChange={ ( value ) => | ||
setAttributes( { | ||
taxonomy: value, | ||
inSameTerm: value === '' ? false : true, | ||
} ) | ||
Comment on lines
+169
to
+172
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. The value of |
||
} | ||
help={ __( | ||
'Only link to posts that have the same taxonomy terms as the current post. For example the same tags or categories.' | ||
) } | ||
/> | ||
</InspectorControls> | ||
<BlockControls> | ||
<AlignmentToolbar | ||
value={ textAlign } | ||
|
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
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.
The pattern category shows in the option in Site Editor unless it is removed here.
If the "New admin views" Gutenberg experiment is enabled, data views also show in the option. I did not hide it since it is still experimental.
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.
Is this conditional statement really necessary? I hesitate to hardcode specific taxonomy slugs into blocks. For example, in a query loop block, no such condition exists.
gutenberg/packages/block-library/src/query/utils.js
Lines 130 to 144 in 55b4e9b
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.
I simply deleted the filter and nothing changed in the interface. I am not sure what changed since November but neither the nav menu, pattern categories or the admin views are showing up now. Custom taxonomies, for standard and for custom post types are showing correctly as well.
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.
I don't know about the navigation menu and admin view, but it seems that
public
has been changed tofalse
in the pattern category.