Skip to content
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

Register Navigation Link block variations based on menu item types added in customizer filters #31584

Closed
wants to merge 8 commits into from

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented May 7, 2021

Description

This PR adds support for the customize_nav_menu_available_items and customize_nav_menu_available_item_types filters in the navigation block and navigation screen.

Fixes #31316.

In order to do so:

  • A new Navigation Link block variation is registered for each menu custom item type returned from customize_nav_menu_available_item_types.
  • A new endpoint has been created so items added in customize_nav_menu_available_items can be queried by the LinkControl component.
  • I fixed some typos and added some missing documentation here and there.

Note: I didn't include any tests yet, before I would like to validate if the approach taken in this PR makes sense.

Testing steps

You can either test with the code snippet example I posted or with real plugins (see section below).

With an example

Paste this PHP code somewhere, simulating it's a plugin adding some nav items:

function add_nav_menu_item_types( $item_types ) {
	$item_types[] = array(
		'title'      => 'Gutenberg Links',
		'type_label' => 'Gutenberg Link',
		'type'       => 'gutenberg_nav',
		'object'     => 'gutenberg_link',
	);

	return $item_types;
}

function add_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) {
	if ( 'gutenberg_link' !== $object ) {
		return $items;
	}

	$gutenberg_items = array(
		array(
			'id'         => 'main',
			'title'      => 'Main site',
			'type_label' => 'Custom Link',
			'url'        => 'https://wordpress.org/gutenberg/',
		),
		array(
			'id'         => 'download',
			'title'      => 'Download page',
			'type_label' => 'Custom Link',
			'url'        => 'https://wordpress.org/plugins/gutenberg/',
		),
		array(
			'id'         => 'repo',
			'title'      => 'Repository',
			'type_label' => 'Custom Link',
			'url'        => 'https://github.com/WordPress/gutenberg',
		),
	);

	return array_merge( $items, $gutenberg_items );
}

add_filter( 'customize_nav_menu_available_item_types', 'add_nav_menu_item_types', 10, 1 );
add_filter( 'customize_nav_menu_available_items', 'add_nav_menu_items', 10, 4 );
  • Create a post or page and add a Navigation block.
  • Inside the Navigation block, add a Gutenberg Link block.
  • Select any of the available options and verify the link is inserted correctly.

Repeat the process in the Navigation screen and widget screen with a classic theme and in the Site Editor with a block-based theme.

With real-life plugins

WooCommerce

Currently, WooCommerce only adds the customize_nav_menu_available_items filter in admin screens, that makes those items not to be available in Rest API calls. I created a branch in WooCommerce's repo which would change this, so in order to test, you will need to check out that branch.

  • In your wp-content/plugins folder clone WC (git clone https://github.com/woocommerce/woocommerce)
  • Go inside the woocommerce folder and checkout the correct branch (git checkout fix/menu-items-in-rest)
  • Build WooCommerce (see docs)
  • Create a post or page and add a Navigation block.
  • Inside the Navigation block, add a WooCommerce endpoint block.
  • Select any of the available options and verify the link is inserted correctly.

Repeat the process in the Navigation screen and widget screen with a classic theme and in the Site Editor with a block-based theme.

BigCommerce

I had trouble enabling BigCommerce in a WP 5.8 site, so what I did was to install BigCommerce in a WP 5.7 and then update WP to 5.8.

Once you have BigCommerce enabled in WP 5.8 (you don't need to create an account to test this PR):

  • Create a post or page and add a Navigation block.
  • Inside the Navigation block, add a BigCommerce navigation link block.
  • Select any of the available options and verify the link is inserted correctly.

Repeat the process in the Navigation screen and widget screen with a classic theme and in the Site Editor with a block-based theme.

Regression testing

It would be good to test other Navigation Link variations to ensure there are no regressions in them:

  • Try adding custom, post and page links to a Navigation block.
  • Do the same with category and tag links.
  • Make sure adding all links worked fine.

Screenshots

WooCommerce menu custom items in the Navigation screen:
Screenshot showing WooCommerce menu custom items

BigCommerce menu custom items in the post editor:
Screenshot showing BigCommerce menu custom items

Types of changes

New feature: register Navigation Link block variations based on the values returned by customize_nav_menu_available_items and customize_nav_menu_available_item_types filters.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

github-actions bot commented May 7, 2021

Size Change: +70 B (0%)

Total Size: 1.04 MB

Filename Size Change
build/block-editor/index.min.js 119 kB -9 B (0%)
build/block-library/index.min.js 145 kB +3 B (0%)
build/components/index.min.js 180 kB +2 B (0%)
build/core-data/index.min.js 12.3 kB +77 B (+1%)
build/edit-post/index.min.js 58.5 kB -1 B (0%)
build/editor/index.min.js 38.6 kB -1 B (0%)
build/format-library/index.min.js 5.68 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.min.js 1.12 kB 0 B
build/annotations/index.min.js 2.93 kB 0 B
build/api-fetch/index.min.js 2.42 kB 0 B
build/autop/index.min.js 2.28 kB 0 B
build/blob/index.min.js 672 B 0 B
build/block-directory/index.min.js 6.61 kB 0 B
build/block-directory/style-rtl.css 989 B 0 B
build/block-directory/style.css 990 B 0 B
build/block-editor/style-rtl.css 13.5 kB 0 B
build/block-editor/style.css 13.5 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/archives/style-rtl.css 65 B 0 B
build/block-library/blocks/archives/style.css 65 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 112 B 0 B
build/block-library/blocks/audio/style.css 112 B 0 B
build/block-library/blocks/audio/theme-rtl.css 125 B 0 B
build/block-library/blocks/audio/theme.css 125 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/button/style-rtl.css 603 B 0 B
build/block-library/blocks/button/style.css 602 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/buttons/style-rtl.css 375 B 0 B
build/block-library/blocks/buttons/style.css 375 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/code/theme-rtl.css 131 B 0 B
build/block-library/blocks/code/theme.css 131 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 422 B 0 B
build/block-library/blocks/columns/style.css 422 B 0 B
build/block-library/blocks/cover/editor-rtl.css 644 B 0 B
build/block-library/blocks/cover/editor.css 646 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB 0 B
build/block-library/blocks/cover/style.css 1.23 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 401 B 0 B
build/block-library/blocks/embed/style.css 400 B 0 B
build/block-library/blocks/embed/theme-rtl.css 124 B 0 B
build/block-library/blocks/embed/theme.css 124 B 0 B
build/block-library/blocks/file/editor-rtl.css 301 B 0 B
build/block-library/blocks/file/editor.css 300 B 0 B
build/block-library/blocks/file/frontend.min.js 773 B 0 B
build/block-library/blocks/file/style-rtl.css 255 B 0 B
build/block-library/blocks/file/style.css 255 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB 0 B
build/block-library/blocks/freeform/editor.css 2.44 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 704 B 0 B
build/block-library/blocks/gallery/editor.css 705 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.06 kB 0 B
build/block-library/blocks/gallery/style.css 1.06 kB 0 B
build/block-library/blocks/gallery/theme-rtl.css 122 B 0 B
build/block-library/blocks/gallery/theme.css 122 B 0 B
build/block-library/blocks/group/editor-rtl.css 160 B 0 B
build/block-library/blocks/group/editor.css 160 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/group/theme-rtl.css 93 B 0 B
build/block-library/blocks/group/theme.css 93 B 0 B
build/block-library/blocks/heading/editor-rtl.css 152 B 0 B
build/block-library/blocks/heading/editor.css 152 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/home-link/style-rtl.css 259 B 0 B
build/block-library/blocks/home-link/style.css 259 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 729 B 0 B
build/block-library/blocks/image/editor.css 727 B 0 B
build/block-library/blocks/image/style-rtl.css 481 B 0 B
build/block-library/blocks/image/style.css 485 B 0 B
build/block-library/blocks/image/theme-rtl.css 124 B 0 B
build/block-library/blocks/image/theme.css 124 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 281 B 0 B
build/block-library/blocks/latest-comments/style.css 282 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 529 B 0 B
build/block-library/blocks/latest-posts/style.css 529 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 176 B 0 B
build/block-library/blocks/media-text/editor.css 176 B 0 B
build/block-library/blocks/media-text/style-rtl.css 492 B 0 B
build/block-library/blocks/media-text/style.css 489 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 633 B 0 B
build/block-library/blocks/navigation-link/editor.css 634 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B 0 B
build/block-library/blocks/navigation-link/style.css 94 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.55 kB 0 B
build/block-library/blocks/navigation/editor.css 1.55 kB 0 B
build/block-library/blocks/navigation/frontend.min.js 2.86 kB 0 B
build/block-library/blocks/navigation/style-rtl.css 1.63 kB 0 B
build/block-library/blocks/navigation/style.css 1.63 kB 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 310 B 0 B
build/block-library/blocks/page-list/editor.css 311 B 0 B
build/block-library/blocks/page-list/style-rtl.css 240 B 0 B
build/block-library/blocks/page-list/style.css 240 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B 0 B
build/block-library/blocks/paragraph/editor.css 157 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 247 B 0 B
build/block-library/blocks/paragraph/style.css 248 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B 0 B
build/block-library/blocks/post-comments-form/style.css 140 B 0 B
build/block-library/blocks/post-comments/style-rtl.css 360 B 0 B
build/block-library/blocks/post-comments/style.css 359 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B 0 B
build/block-library/blocks/post-excerpt/style.css 69 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 141 B 0 B
build/block-library/blocks/post-featured-image/style.css 141 B 0 B
build/block-library/blocks/post-template/editor-rtl.css 100 B 0 B
build/block-library/blocks/post-template/editor.css 99 B 0 B
build/block-library/blocks/post-template/style-rtl.css 379 B 0 B
build/block-library/blocks/post-template/style.css 380 B 0 B
build/block-library/blocks/post-title/style-rtl.css 60 B 0 B
build/block-library/blocks/post-title/style.css 60 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 103 B 0 B
build/block-library/blocks/preformatted/style.css 103 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 318 B 0 B
build/block-library/blocks/pullquote/style.css 318 B 0 B
build/block-library/blocks/pullquote/theme-rtl.css 169 B 0 B
build/block-library/blocks/pullquote/theme.css 169 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query-title/editor-rtl.css 86 B 0 B
build/block-library/blocks/query-title/editor.css 86 B 0 B
build/block-library/blocks/query/editor-rtl.css 131 B 0 B
build/block-library/blocks/query/editor.css 132 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/quote/theme-rtl.css 221 B 0 B
build/block-library/blocks/quote/theme.css 221 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/editor-rtl.css 211 B 0 B
build/block-library/blocks/search/editor.css 211 B 0 B
build/block-library/blocks/search/style-rtl.css 359 B 0 B
build/block-library/blocks/search/style.css 362 B 0 B
build/block-library/blocks/search/theme-rtl.css 64 B 0 B
build/block-library/blocks/search/theme.css 64 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 251 B 0 B
build/block-library/blocks/separator/style.css 251 B 0 B
build/block-library/blocks/separator/theme-rtl.css 172 B 0 B
build/block-library/blocks/separator/theme.css 172 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 512 B 0 B
build/block-library/blocks/shortcode/editor.css 512 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 440 B 0 B
build/block-library/blocks/site-logo/editor.css 441 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 154 B 0 B
build/block-library/blocks/site-logo/style.css 154 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 800 B 0 B
build/block-library/blocks/social-links/editor.css 799 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.34 kB 0 B
build/block-library/blocks/social-links/style.css 1.34 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 308 B 0 B
build/block-library/blocks/spacer/editor.css 308 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 480 B 0 B
build/block-library/blocks/table/style.css 480 B 0 B
build/block-library/blocks/table/theme-rtl.css 188 B 0 B
build/block-library/blocks/table/theme.css 188 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 551 B 0 B
build/block-library/blocks/template-part/editor.css 550 B 0 B
build/block-library/blocks/template-part/theme-rtl.css 101 B 0 B
build/block-library/blocks/template-part/theme.css 101 B 0 B
build/block-library/blocks/term-description/editor-rtl.css 90 B 0 B
build/block-library/blocks/term-description/editor.css 90 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/blocks/video/editor-rtl.css 569 B 0 B
build/block-library/blocks/video/editor.css 570 B 0 B
build/block-library/blocks/video/style-rtl.css 173 B 0 B
build/block-library/blocks/video/style.css 173 B 0 B
build/block-library/blocks/video/theme-rtl.css 124 B 0 B
build/block-library/blocks/video/theme.css 124 B 0 B
build/block-library/common-rtl.css 1.26 kB 0 B
build/block-library/common.css 1.26 kB 0 B
build/block-library/editor-rtl.css 9.68 kB 0 B
build/block-library/editor.css 9.67 kB 0 B
build/block-library/reset-rtl.css 506 B 0 B
build/block-library/reset.css 507 B 0 B
build/block-library/style-rtl.css 10.2 kB 0 B
build/block-library/style.css 10.2 kB 0 B
build/block-library/theme-rtl.css 692 B 0 B
build/block-library/theme.css 693 B 0 B
build/block-serialization-default-parser/index.min.js 1.3 kB 0 B
build/block-serialization-spec-parser/index.min.js 3.06 kB 0 B
build/blocks/index.min.js 47.2 kB 0 B
build/components/style-rtl.css 16.2 kB 0 B
build/components/style.css 16.1 kB 0 B
build/compose/index.min.js 10.2 kB 0 B
build/customize-widgets/index.min.js 9.97 kB 0 B
build/customize-widgets/style-rtl.css 1.45 kB 0 B
build/customize-widgets/style.css 1.45 kB 0 B
build/data-controls/index.min.js 829 B 0 B
build/data/index.min.js 7.22 kB 0 B
build/date/index.min.js 31.8 kB 0 B
build/deprecated/index.min.js 739 B 0 B
build/dom-ready/index.min.js 576 B 0 B
build/dom/index.min.js 4.62 kB 0 B
build/edit-navigation/index.min.js 14 kB 0 B
build/edit-navigation/style-rtl.css 3.08 kB 0 B
build/edit-navigation/style.css 3.08 kB 0 B
build/edit-post/classic-rtl.css 454 B 0 B
build/edit-post/classic.css 454 B 0 B
build/edit-post/style-rtl.css 7.05 kB 0 B
build/edit-post/style.css 7.04 kB 0 B
build/edit-site/index.min.js 25.9 kB 0 B
build/edit-site/style-rtl.css 4.75 kB 0 B
build/edit-site/style.css 4.75 kB 0 B
build/edit-widgets/index.min.js 16 kB 0 B
build/edit-widgets/style-rtl.css 3.45 kB 0 B
build/edit-widgets/style.css 3.45 kB 0 B
build/editor/style-rtl.css 3.91 kB 0 B
build/editor/style.css 3.9 kB 0 B
build/element/index.min.js 3.44 kB 0 B
build/escape-html/index.min.js 739 B 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/hooks/index.min.js 1.76 kB 0 B
build/html-entities/index.min.js 628 B 0 B
build/i18n/index.min.js 3.73 kB 0 B
build/is-shallow-equal/index.min.js 709 B 0 B
build/keyboard-shortcuts/index.min.js 1.74 kB 0 B
build/keycodes/index.min.js 1.43 kB 0 B
build/list-reusable-blocks/index.min.js 2.07 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.min.js 3.08 kB 0 B
build/notices/index.min.js 1.07 kB 0 B
build/nux/index.min.js 2.31 kB 0 B
build/nux/style-rtl.css 718 B 0 B
build/nux/style.css 716 B 0 B
build/plugins/index.min.js 1.99 kB 0 B
build/primitives/index.min.js 1.03 kB 0 B
build/priority-queue/index.min.js 791 B 0 B
build/react-i18n/index.min.js 924 B 0 B
build/redux-routine/index.min.js 2.82 kB 0 B
build/reusable-blocks/index.min.js 2.56 kB 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/rich-text/index.min.js 10.6 kB 0 B
build/server-side-render/index.min.js 1.64 kB 0 B
build/shortcode/index.min.js 1.68 kB 0 B
build/token-list/index.min.js 847 B 0 B
build/url/index.min.js 1.95 kB 0 B
build/viewport/index.min.js 1.28 kB 0 B
build/warning/index.min.js 1.13 kB 0 B
build/widgets/index.min.js 6.48 kB 0 B
build/widgets/style-rtl.css 693 B 0 B
build/widgets/style.css 693 B 0 B
build/wordcount/index.min.js 1.24 kB 0 B

compressed-size-action

@Aljullu Aljullu force-pushed the fix/31316-honor-customize-filters-navigation branch 2 times, most recently from 940e8d0 to c79bae3 Compare May 7, 2021 08:41
@talldan talldan requested a review from gwwar May 7, 2021 09:11
@getdave getdave self-requested a review May 13, 2021 15:07
@getdave
Copy link
Contributor

getdave commented May 13, 2021

Thank you for raising this PR. It looks really interesting and I'm pleased that we have an approach to catering for these existing filters.

Obviously, this is quite a large PR so ultimately (not yet - let's review first) we might want to break it up into PRs for:

  • REST API endpoint.
  • Additional of new API to @wordpress/core-data.
  • Modifications to LinkControl.
  • Modifications to the Navigation block.

That should make it easier to review and (given the pace of development in Gutenberg at the moment) introduce without too many rebases along the way.

I'm going to experiment with the branch as per your instructions and start to wrap my head around what's going on and whether there are any other angles to explore. Initially, however, this seems to fit together well.

@getdave getdave added this to PRs pending review in Navigation editor via automation May 13, 2021
@Mamaduka
Copy link
Member

Hello, @Aljullu

Thanks for working on this.

I agree with @getdave that splitting this into smaller PR will make reviews easier.

One thing that I'm not certain about is if we should use customize_nav_menu_available_* filters. These are Customizer-specific filters and currently not support on the Menus screen.

Maybe we should introduce new navigation screen-specific filters for adding custom variations and fetching suggestions.

@Aljullu
Copy link
Contributor Author

Aljullu commented May 18, 2021

Thanks for the answers @getdave and @Mamaduka!

One thing that I'm not certain about is if we should use customize_nav_menu_available_* filters. These are Customizer-specific filters and currently not support on the Menus screen.

Maybe we should introduce new navigation screen-specific filters for adding custom variations and fetching suggestions.

From my understanding, there were two ways plugins were adding custom menu items (at least, that's what WooCommerce is doing):

  • The customize_nav_menu_available_items and customize_nav_menu_available_item_types filters for the customizer screen.
  • add_meta_box() inside the action admin_head-nav-menus.php for the menu screen.

The issue with the second approach is that it needs to add a lot of boilerplate HTML to create the meta box layout, while the first approach seems cleaner.

It's true, however, that the filter names might not be the most appropriate for the block-based navigation screen. I used those filter names to keep it backwards-compatible, but we could rename them and deprecate (but still support) the old filter names. Is that what you were proposing?

I agree with @getdave that splitting this into smaller PR will make reviews easier.

Will do! 🙂 I just want to make sure we agree on a path forward before opening new PRs for this.

@Mamaduka
Copy link
Member

The issue with the second approach is that it needs to add a lot of boilerplate HTML to create the meta box layout, while the first approach seems cleaner.

Yes, the current method for adding custom menu items to the menu screen isn't ideal.

Maybe we can add nav_menu_available_items and nav_menu_available_item_types filters, that will have same signature as customizer ones.

This will make it easier for plugins to opt-in new Navigation screen support by adding another filter for the same callback.

@gwwar
Copy link
Contributor

gwwar commented May 18, 2021

Before we chat through implementation details, I want to better understand the problem this is solving.

So broadly, would we say we'd like for a site to define some set of links which are insertable in the navigation block? Are these links dynamic? How are they special/different from custom links and do we have any other examples besides WooCommerce?

@Mamaduka
Copy link
Member

So broadly, would we say we'd like for a site to define some set of links which are insertable in the navigation block?

Yes, that's correct.

These links can be dynamic or not. Most of the time, they're inserted as "Custom Link" type. I know that BuddyPress also uses this method, and based on my quick search of the WP.org repo, there are 20 other plugins.

Search results: https://wpdirectory.net/search/01F61B3YJ3XNDYPJS2PCYW8HEZ

@Aljullu
Copy link
Contributor Author

Aljullu commented May 24, 2021

Maybe we can add nav_menu_available_items and nav_menu_available_item_types filters, that will have same signature as customizer ones.

@Mamaduka That sounds good to me. The idea would be that the Navigation screen would only apply these new filters and extensions would need to register filters for the legacy and new hooks?

Are these links dynamic? How are they special/different from custom links and do we have any other examples besides WooCommerce?

@gwwar Those links are not dynamic, once added they are just regular 'custom links', at least, this is the case for WooCommerce. The utility of those filters is so plugins can offer a set of links that users can choose from without the need to introduce the URL (which the user might not know at all).

@getdave
Copy link
Contributor

getdave commented May 26, 2021

@Aljullu I've tried several times to get a WooCommerce build up and running but unfortunately I keep hitting memory limits.

For ease of testing and for the benefit of other reviewers, would you be able to add some code directly to this PR (or in a comment) that utilises the functionality being added by this PR?

It really just needs to exercise the new APIs you've created so we can review.

I feel that's going to make the process of getting feedback here a lot easier. Let us know if you're able to do that.

Much appreciated.

@Aljullu
Copy link
Contributor Author

Aljullu commented May 26, 2021

@getdave done! 👍 I updated the PR description with a PHP snippet that can be used to test this PR, let me know if it works.

Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @Aljullu. I'm leaving a bit of higher level feedback to 🤔 through.

Overall, I do think this is a pretty good use case to support, but I'm not sure of how this should be displayed to a user in the block editors.

How many custom links does a plugin typically register? Is it something like a handful like 5 or a lot like 1000+? If it's closer to a handful we could maybe embed this within a script or the block variation data itself. If it's a lot, some REST endpoint makes more sense. (Whether this is new or an extended extended endpoint I'll defer to API component owners).

Another thing that could use some thought is discoverability of said custom links. By default, link suggestions only displays 3 links. How will a user know to search for items they didn't create? Maybe @jasmussen has some ideas?

custom.links.mp4

@jasmussen
Copy link
Contributor

jasmussen commented Jun 9, 2021

This is definitely tricky from a UI point of view. As Kerry points out, the more child blocks we add, the harder it is to find the right one to insert. It's already grown to a point where the experience isn't ideal:

Screenshot 2021-06-09 at 09 19 54

The fact that it's a two-step process: insert block type first, and then choose the contents of that block type is likely a source of confusion for a user who inserts a navigation block and then expects the plus button to let them immediately add a link.

But that's how the block editor works — first you insert the block, and then you configure the block. Patterns is a key interface we can use to smooth this out.

And that brings me to the next item — navigation block patterns will likely have menu items, search, spacers, site titles, social links preinserted. They will not pre-insert a block type that isn't part of the vanilla offering. Which means any blocks you extend with here, have to be inserted by the user as they are building their menu — they won't be able to leverage patterns.

Even now, we have both "Page Link", and "Custom Link" blocks to insert. They are technically the same, mostly — you can search for a Page in the custom Link block, or you can paste an external URL in the Page Link block:

Screenshot 2021-06-09 at 09 19 37

But I'm increasingly not sure the distinction between the two is valuable, since they both do the same. And by adding additional "link type" blocks, it will only serve to make the two-step flow that much more clunky.

Have you considered, instead of registering new link type blocks, to extend or expand the URL dialog instead? Instead of this one:

Screenshot 2021-06-09 at 09 20 32

In the end, a menu item is just a text label and a link, with affordances for choosing that link. We might just want to let you pick that link interface? This is a rough sketch that needs time in the oven (perhaps something better than a dropdown to choose the type), but hopefully it illustrates the idea:

Screenshot 2021-06-09 at 09 36 41

See also #24099.

@Aljullu
Copy link
Contributor Author

Aljullu commented Jun 9, 2021

Thank you all for the feedback and ideas!

@gwwar:

How many custom links does a plugin typically register? Is it something like a handful like 5 or a lot like 1000+?

I don't have any data, but from my tests with WooCommerce, BuddyPress and BigCommerce, it looks like they add less than a dozen links each.

If it's closer to a handful we could maybe embed this within a script or the block variation data itself. If it's a lot, some REST endpoint makes more sense. (Whether this is new or an extended extended endpoint I'll defer to API component owners).

Do you have an example of what "within a script or the block variation data itself" would look like? That's an approach I experimented with in the beginning, but couldn't figure out how to get working. Is your proposal similar to @spacedmonkey's to use a localize script?

@jasmussen:

Have you considered, instead of registering new link type blocks, to extend or expand the URL dialog instead?

Sure thing, that's one of the 'alternative implementations' that I considered in #31316. I didn't take that route for a couple of reasons:

  • The custom menu link items are not a real post/page or any other content type. So, as a user, I might be confused on where to search those options. Following WC's example (the one that is more familiar to me): as a user I want to add a link to Orders, but I know there is no Orders page when I visit the All Pages admin page. Would it be clear I need to add a Page Link or Custom Link to find that option?
  • This is mostly a technical one, but I didn't find any extensibility points that would allow me to hook into the pages API response. It should be possible to add these extensibility points, but pointing out that AFAIK they don't currently exist.
  • UI-wise, I wonder if it's better to have different block variations for each plugin or to have all plugins hook into the Page Link or Custom Link variation? If a site has WooCommerce and BuddyPress installed, will it be easy to find blocks relative to each plugin? In addition to that, BuddyPress seems to separate the links between logged-in and logged-out, how could that be presented in the UI?

Notice none of these reasons are blocking and I'm completely fine exploring the route of extending the URL dialog instead of creating new Navigation Link block variations, but I wanted to expose some of the reasons that made me try the latter approach first.

@jasmussen
Copy link
Contributor

Notice none of these reasons are blocking and I'm completely fine exploring the route of extending the URL dialog instead of creating new Navigation Link block variations, but I wanted to expose some of the reasons that made me try the latter approach first.

Thank you, that's awesome.

I'm trying to go back to the initial use case meant to be solved by this. It may have made sense for a dedicated navigation screen that is primarily intended for organizing navigation items. But the new navigation block isn't just links. In that context, having to pick between multiple different types of links, I'm not convinced, is the best user experience. It makes sense for the "Home Link" as that's kind of a disparate thing with little to no configuration. But even the separation between Page Link and Custom Link is spurious.

To be clear, separate blocks might still be the correct path forward for the API. But it's a path I suspect that should be paired with improvements to the quick inserter, and yes, possibly also improvements to the link dialog. I'd appreciate a wider range of thoughts here: @draganescu @mcsf if you have time, thank you.

@gwwar
Copy link
Contributor

gwwar commented Jun 9, 2021

Do you have an example of what "within a script or the block variation data itself"

@Aljullu this depends on what flow we ultimately end up with. I'd see if we can get folks to align on a user flow in the block editor first. What's important here is that if most plugins only need a few items, both an API endpoint and some other mechanism like passing an array of links in a hook can be viable.

In that context, having to pick between multiple different types of links, I'm not convinced, is the best user experience. It makes sense for the "Home Link" as that's kind of a disparate thing with little to no configuration. But even the separation between Page Link and Custom Link is spurious.

@jasmussen thanks for the insights here! Each custom post type may also be registered as a navigation block variant, so I wonder if we'll need to help fix this in future PRs.

Going back to this PR. One thing I'm reminded of is that since we're working with static link content, I'm actually wondering if a block pattern is a better fit. 🤔 Perhaps we could apply a pattern as an option to the initial navigation placeholder?

https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/

@@ -105,6 +105,13 @@ Whether to present suggestions when typing the URL.

Whether to present initial suggestions immediately.

### noDirectEntry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's unrelated to the other changes in that PR. It's a prop that was undocumented. I thought all props had to be in the docs, but happy to remove it from here if not.

@draganescu
Copy link
Contributor

draganescu commented Jun 14, 2021

TLDR We should probably drop this link block variation idea altogether.

The path in this PR is basically using the same system that the default variations use, so I don't think it's wrong.

As a user I want to add a link to "place" by adding a link block and linking it to "place". If "place" is not an URL the link block should do its best to suggest the best match, based on me entering "place" in the search box.

Based on this story, we should allow users to search for Home, Front page, Orders, Cart, Members, Profile, All forums or whatever kind of special places the system provides, and which have dynamic, generated locations. Just as the user can search in posts or pages by their title.

I don't think these variations are a great win. We did copy the way the old screen behaved, but TBH, that screen did not have a live query UI which can be extended to respond quite smartly. We now have a single entry point, a search box, the most common UX. Why do we need to feature "post link", "custom link", "orders link"? Is the win worth the problem?

We also used a variation so that we can show default suggestions that match. Say I insert a Page link I see most recent pages. But is this extra step worth it considering I have a search box which looks through all the "stuff" on my site (ideally it should search everything, including media)? Don't we just create an assumption for no reason that all "link types" (a concept which is foreign to the web) should now have a button?

The only other problem still remaining is that all links except custom (aka manually entered) links shoud not be static as they're depending on various system settings.

@talldan
Copy link
Contributor

talldan commented Jun 15, 2021

Agree with the general consensus that the number of variations exposed in the inserter can be confusing.

I don't think it'd be a problem to hide most or all of them from the inserter, the type of link selected from the link interface can (and I think already does) determine the variation.

The linking interface might need some improvements to cater for the amount of items a user can search for. That could probably tie in with the possibility of bulk adding links - #31667.

@Aljullu Aljullu force-pushed the fix/31316-honor-customize-filters-navigation branch from 17d4d17 to 6e73864 Compare June 17, 2021 12:56
@Aljullu Aljullu force-pushed the fix/31316-honor-customize-filters-navigation branch from 6e73864 to 5c34f3b Compare June 17, 2021 13:00
@Aljullu
Copy link
Contributor Author

Aljullu commented Jun 18, 2021

Thanks for the feedback and all ideas in this PR. I applied some of the suggestions, but my understanding is that some others need some design/product decisions. I tried to gather all ideas below (please, feel free to add new ones or edit them if you feel I didn't explain them right):

  • Create a Navigation link block variation. This is how it's done in this PR. Currently, data is retrieved from a newly-created endpoint, but two alternatives were proposed:
    • moving the endpoint to /wp/v2/menu-items/custom.
    • directly embedding the data, so there wouldn't be the need to create an endpoint.
  • Extend or expand the URL dialog so endpoints added by extensions are presented as options in the Page Link block variation. That means there is no need to create new block variations for extension endpoints.
  • Use patterns instead of block variations.
  • Use a generic Link block that would also allow us to merge other Navigation Link block variations: Page Link, Post Link, etc. So all links, independently of their type, would be added through the same block.

I will need some guidance on moving this forward because I don't think I'm entitled to make a decision on what approach is better. Also, I think it would be great to distinguish what should be fixed as part of this PR and what can be done as follow-ups.

@jasmussen
Copy link
Contributor

Thanks for all the work here. I'd like to offer thoughts on at least what we should avoid:

  • Patterns should always be features we make in addition to a good basic user experience. It's great if a user can use patterns for their entire flow, but it can never be a replacement for a good baseline.
  • Extending URL dialogs can likely be an improvement not just to this block but to many others, and likely something we'll want to do regardless of what we do here. Because it's not just in the navigation block where you might want to link to these types of destinations.

At the same time, consolidating on a single Menu Item block doesn't really work that well unless paired with an upgraded URL picker. So to an extent there's a bit of a meta conversation, essentially repeating what @draganescu said:

  • Do we think of destination types (post, page, tag, category, cpt, shopping cart) as something that should be available wherever you can make a link?
  • Or do we think of each of these as block types?

If we think the latter, then it should be blocks using the existing transform API, so we avoid building stuff just for this one block. Even if we find it necessary to go with blocks (whether for API or pragmatic/move forward reasons), improvements to the quick inserter can help. For example we might want to tailor the default block suggestions, and only surface others when searched for.

@mtias had thoughts on this with the Home Link block, curious what your take is.

@Thelmachido
Copy link

@Aljullu there hasn't been much activity on this PR in a while, just checking if there is still a plan to continue working on this.

I have removed the Navigation Screen label since the project was moved to an inactive status on the feature projects page in coordination with the project leads. However, the work can be continued with the navigation block.

@Aljullu
Copy link
Contributor Author

Aljullu commented Sep 21, 2022

@Aljullu there hasn't been much activity on this PR in a while, just checking if there is still a plan to continue working on this.

I think we can close this PR given the feedback that was provided, I experimented with an alternative approach in #35876. Thanks for the heads-up, @Thelmachido!

@Aljullu Aljullu closed this Sep 21, 2022
Navigation editor automation moved this from PRs pending review to Done Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Feature] Extensibility The ability to extend blocks or the editing experience
Projects
No open projects
10 participants