Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#52688 closed enhancement (fixed)

Make block type aware of variations

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

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)

#1 @gwwar
6 years ago

  • Component General → Editor
  • Keywords has-patch added

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


6 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.

​https://user-images.githubusercontent.com/1270189/109558000-b32d4d00-7a8d-11eb-8c23-64fb90ed9c6e.mp4

### 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">

​gziolo commented on ​PR #1015:


6 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 @gziolo
6 years ago

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

#5 @gziolo
6 years ago

  • Resolution → fixed
  • Status assigned → 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
6 years 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.