gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Add new hook to allow additional featured block

Open Hug0-Drelon opened this issue 3 years ago • 10 comments

Fixes https://github.com/WordPress/gutenberg/issues/39814

What?

Introduce a new filter to allow adding blocks in the navigation transform control panel.

Why?

This could be useful for third party plugins to feature their custom blocks and for the user to use it easily.

Testing Instructions

This PR can be manually tested after creating and registering a custom block and adding something like:

const featureNavigationCustomBlock = ( blockNames ) => {
    return blockNames.concat( [ 'my-plugin/my-custom-block' ] );
}

addFilter( 'allow_additional_featured_block_in_navigation', 'my-plugin/add_my_custom_block_to_featured_blocks', featureNavigationCustomBlock );

Your custom block feature should be displayed here: Capture d’écran 2022-03-28 à 15 52 44

Hug0-Drelon avatar Mar 28 '22 15:03 Hug0-Drelon

Thanks for working on this. I agree with @getdave about opening it up to an arbitrary number of blocks. The design starts to look wrong with four. A filter could probably still support only three by disregarding anything after the third item as long as that's clearly documented.

Another option for deciding which three blocks to show could be to use the priority field that block transforms already have (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-transforms/#block). The first three block with the highest priority could be shown. I don't know if that would be highjacking the priority system a bit. Any drawbacks anyone can think of?

Anyway, I think the core issue here is that it's still really quite hard to insert non-link blocks. I don't think https://github.com/WordPress/gutenberg/issues/34041 was ever solved completely. It's now easy to insert a Link, not too difficult to insert a Search, Site Logo, or Social Icons, but very confusing to insert anything else.

talldan avatar Mar 30 '22 08:03 talldan

@talldan, I liked the idea of the variation approach you mentioned here - https://github.com/WordPress/gutenberg/pull/36026#issuecomment-954487319. Maybe we can introduce a new variation scope (navigation) instead of a new filter.

I agreed that the design would need to adjust.

Mamaduka avatar Mar 30 '22 08:03 Mamaduka

Thank you all for your feedback 😃

@getdave I understand your concerns about having too many blocks displayed in the transform control panel. But I don't think that many plugins would insert blocks here, even less from a user point of view IMHO. Although I understand UI has to be controlled. Maybe we could imagine a "show more" button like this: Capture d’écran 2022-03-30 à 19 13 56 (sorry for the bad design 🤣 ) Whit that, the number of displayed block is under control and we can still show more options (accepting that the panel would grow in space).

The idea of handling the displayed blocks through a priority seems to be easily implemented but everyone will require the first place in their code (that's what I'd do 😅 ). And the rendering won't be predictable by potentially hiding some custom blocks (which we want to avoid). But maybe I misunderstood your point.

As for the variation approach, I must say I'm not really qualified about this way of doing (newbie here ahah). So I won't dare to propose something.

Hug0-Drelon avatar Mar 30 '22 17:03 Hug0-Drelon

While the filter should be considered in the context of @talldan 's point that the design is not really "extensible" yet, I also don't think this particular solution solves #39814. The idea is for the user to be able to insert that language switcher. Should plugins be allowed to turn off the default behaviour of inserting links, and have the inserter open instead?

draganescu avatar Apr 01 '22 18:04 draganescu

@draganescu You're right, the proposed solution is only a workaround. From a user point of view, the easiest way would be to insert the plugin's block directly (and not transform a link into something else). So opening the inserter to plugins could be the best way to go. I thought that the behavior of only being able to insert links was designed on purpose, that's why I proposed this filter.

Hug0-Drelon avatar Apr 01 '22 19:04 Hug0-Drelon

Hi 👋 Any thought on how to handle this ? I'd be glad to make another PR if needed 😉

Hug0-Drelon avatar Apr 29 '22 05:04 Hug0-Drelon

@Hug0-Drelon I added design related labels, but what seems from reading above to be the blocker is to figure out how the UX for solving what @talldan described as

I think the core issue here is that it's still really quite hard to insert non-link blocks.

Bringing this PR and its associated issue up in design channels in core is also a good start. Briefly, it's not the code that is the major problem but the interaction.

draganescu avatar May 17 '22 09:05 draganescu

It looks like this needs feedback not design so I'm just adjusting labels.

karmatosed avatar May 31 '25 14:05 karmatosed

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Hug0-Drelon <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: draganescu <[email protected]>
Co-authored-by: karmatosed <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

github-actions[bot] avatar May 31 '25 14:05 github-actions[bot]

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: Needs Design Feedback.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

github-actions[bot] avatar May 31 '25 14:05 github-actions[bot]