Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#52688 closed enhancement (fixed)

Make block type aware of variations

Reported by: gwwar Owned by: gziolo
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch has-unit-tests commit
Focuses: Cc:


Currently block variations (not style variations) are only defined on the client. In some cases, creating block variations on the server can be very useful, especially when needed data is not exposed in the REST APIs.

I have an example use case for adding navigation link variations. The navigation block currently allows insertion of Links, Post Links, Page Links, Tag Links and Category Links. By adding server link variations, if we install a Portfolio plugin for example, we should also be able to add Portfolio Links. The taxonomy and post type REST API doesn't allow filtering by show_in_nav_menus, so server defined block variations makes this a much easier problem to solve.

Example Use Case Issue: https://github.com/WordPress/gutenberg/issues/24814

Proposed PR: https://github.com/WordPress/wordpress-develop/pull/1015

Change History (7)

#1 @gwwar
9 months ago

  • Component changed from General to Editor
  • Keywords has-patch added

This ticket was mentioned in PR #1015 on WordPress/wordpress-develop by gwwar.

9 months ago

  • Keywords has-unit-tests added


Experiment, required for https://github.com/WordPress/gutenberg/pull/29095

This PR exposes variations in the block type definition and adds two new labels item_link and item_link_description for post types and taxonomies.

Changes here will allow us to populate link navigation variations via register_block_type_from_metadata without needing to update the post type and taxonomy REST APIs to allow filtering by show_in_nav_menus.

### Testing Instructions

  • Checkout and run this branch locally with an environment of your choice. (Don't forget to npm run build)
  • Test the GET REST endpoint /wp/v2/block-types. Notice how there is a new variations field returned.
  • Make sure local tests pass by running npm run test:php -- --filter REST_Block_Type_Controller_Test

<img width="951" alt="Screen Shot 2021-02-24 at 8 31 02 PM" src="https://user-images.githubusercontent.com/1270189/109103202-49a0ed80-76df-11eb-8238-6e6fb389411a.png">

If you like, also follow test instructions in https://github.com/WordPress/gutenberg/pull/29095.


### Default label behavior

<img width="1397" alt="Screen Shot 2021-03-01 at 12 34 45 PM" src="https://user-images.githubusercontent.com/1270189/109559265-4d41c500-7a8f-11eb-8e5d-6dca934d8188.png">

#3 @prbot
9 months ago

gziolo commented on PR #1015:

I'm adding the Trac ticket to my list of items to take care of later this week. I want to wait until WordPress 5.7 is out before committing. Nice work @gwwar ✨

#4 @gziolo
9 months ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.8
  • Owner set to gziolo
  • Status changed from new to assigned

#5 @gziolo
9 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 50527:

Editor: Make block type aware of variations

Currently block variations are only defined on the client. In some cases, creating block variations on the server can be very useful, especially when needed data is not exposed in the REST APIs.

Related to https://github.com/WordPress/gutenberg/pull/29095.

Props: gwwar, timothyblynjacobs.
Fixes: #52688.

#7 @SergeyBiryukov
9 months ago

In 50529:

Docs: Add missing @since tags for item_link and item_link_description post type and taxonomy labels.

Follow-up to [50527].

See #52688.

Note: See TracTickets for help on using tickets.