Open bobbingwide opened 3 years ago
Here's a screenshot showing the Post link variations for the Navigation block
It also shows a subset of the Block list with Show batch commands toggled on.
In #core-editor, in response to
I have a question regarding core/navigation-link blocks. With WordPress 5.8 and Gutenberg 10.9.2 I see many Category Link, Post Link, Page Link and Tag Link variations - one per CPT / taxonomy. What was the PR for this change?
I was pointed to https://github.com/WordPress/gutenberg/issues/24814
which I'd commented on a long time ago, the most recent of which was https://github.com/WordPress/gutenberg/issues/24814#issuecomment-789094404 in which I wrote.
It will be interesting to see how unwieldy the navigation blocks become with one variation per post type and taxonomy. I'm using at least a dozen CPTs, some of which have 3 taxonomies, and some of these taxonomies are shared between post types. Additionally, for my A to Z letter pagination menu(s) each link needs the post type as well as the taxonomy term. eg.
https://blocks.wp-a2z.org/letters/g/?post_type=oik-plugins
shows Plugins with the first letter G. Compare withhttps://blocks.wp-a2z.org/letters/f/?post_type=oik-themes
which shows Themes with first letter F.
I was also advised what to do to control the display of and identify each variation.
show_in_nav_menus
false. See https://developer.wordpress.org/reference/functions/register_post_type/#show_in_nav_menusitem_link
and item_link_description
in the CPT registration.This is what WooCommerce must have done for Product Category Link and Product Tag Link.
For the Block list block, when used in blocks.wp-a2z.org, it might make sense to shortcircuit these Link variations. This could be achieved by removing the action hook which is used to register the variations.
add_action( 'init', 'gutenberg_register_block_core_navigation_link', 20 );
or we could filter the variations for the block registration
register_block_type_from_metadata(
__DIR__ . '/navigation-link',
array(
'render_callback' => 'render_block_core_navigation_link',
'variations' => array_merge( $built_ins, $variations ),
)
);
by hooking into block_type_metadata
OK, so I managed to prevent the variations from being registered in the server. But the defaults are still listed in the editor, so I assume these are still being registered in the JavaScript.
Now I want to see how to filter the variations to give them better names or should I just change the registration of the CPTs and taxonomies and be done with it?
[variations] => Array
(
[0] => Array
(
[name] => post
[title] => Post Link
[description] => A link to a post.
[attributes] => Array
(
[type] => post
[kind] => post-type
)
)
The 5 default's names are: post, page, category, tag and post_format
Other CPTs and taxonomies have different values for the name
.
The value of attributes.type
matches the name
.
or should I just change the registration of the CPTs and taxonomies and be done with it?
I changed bw_default_labels()
but it didn't work until I deactivated oik-types.
This is because oik-types stores out of date information in the options table.
In this case it's the labels
array not containing all the strings, eg item_link
and item_link_description
.
With oik-types activated there are two scenarios that need addressing, both of which are for CPTs that were defined/updated in oik-types before the missing labels were added.
oikcpt_adjust_args()
labels
before calling bw_register_post_type()
.Check that this solution works for post types with different singular and plural names.
When analysing the block changes between Gutenberg 10.7.0 and the latest (11.6.0) I noted that the number of blocks and variations with WordPress 5.7.2 changed from 178 to 177 with Gutenberg 10.9.0, but with WordPress 5.8.0 there were many variations of the
core/navigation-link
block, giving 205 blocks and variations.eg in blocks.wp.a2z the additional variations were:
but the list didn't include
Custom Link - core/navigation-link