#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: |
Description
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)
This ticket was mentioned in PR #1015 on WordPress/wordpress-develop by gwwar.
4 years ago
#2
- Keywords has-unit-tests added
https://core.trac.wordpress.org/ticket/52688
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">
4 years ago
#3
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
@
4 years ago
- Keywords commit added
- Milestone changed from Awaiting Review to 5.8
- Owner set to gziolo
- Status changed from new to assigned
I have a proposed patch in:
https://github.com/WordPress/wordpress-develop/pull/1015