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

Rough POC of respecting "supports multiple" in the auto-inserted block metadata #53925

Closed
wants to merge 1 commit into from

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Aug 24, 2023

What?

A very rough proof of concept of having the new auto-insert block API (#51449) respect the supports multiple configuration in the block.json of the block configuring auto-insertion.

This PR is definitely not ready for merge as is but could be shaped towards it.

Why?

There are cases where blocks are registered to have only one instance of the block in the layout and this is typically configured using the supports.multiple property in block.json. Currently, the auto-insertion does not respect this property and this PR demonstrates a potential path to doing so.

An important caveat: this has no control over what instance of an anchor block the auto insertion will kick in. If the blocks has supports.multiple defined as false, then the block will only be inserted in the first instance of the anchor block.

Testing Instructions

  1. Register a block using the __experimentalAutoInsert property in block.json
  2. Ensure the supports.multiple property in block.json is set to false.
  3. Test a template/pattern with multiple instances of the anchor block and verify the inserted block only appears once.

Testing Instructions for Keyboard

Screenshots or screencast

@github-actions
Copy link

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/experimental/auto-inserting-blocks.php

@nerrad
Copy link
Contributor Author

nerrad commented Aug 30, 2023

Something else we'd have to consider as a part of this stream is how to handle things if the block being inserted is already present in the content? I don't think the block should be auto-inserted in this case (when multiple:false).

@gziolo
Copy link
Member

gziolo commented Aug 31, 2023

I remember we discussed during WC US that sometimes plugin developers would like to decide whether the block should get auto-inserted only once, but not necessarily in the first matching spot, but maybe last. I believe we should build a general function that performs basic checks informed by existing block API, and integrate a WP filter to offer ways to prevent insertion based on custom conditions.

@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. labels Aug 31, 2023
@nerrad
Copy link
Contributor Author

nerrad commented Sep 5, 2023

I believe we should build a general function that performs basic checks informed by existing block API, and integrate a WP filter to offer ways to prevent insertion based on custom conditions.

I like this approach, we would need to ensure there is any helpful context provided to the filter (outside of what may be exposed globally by WordPress to callbacks).

@gziolo
Copy link
Member

gziolo commented Sep 6, 2023

I left a comment that contemplates on the complexity of adding support for supports.multiple and other similar existing APIs for blocks in #53987 (comment).

@nerrad
Copy link
Contributor Author

nerrad commented Sep 6, 2023

To reduce clutter, I'm going to close this PR - it was always intended as a reference POC and has generated some useful discussion :)

@nerrad nerrad closed this Sep 6, 2023
@gziolo gziolo deleted the try/respect-multiple-on-auto-insert branch September 6, 2023 15:38
@gziolo
Copy link
Member

gziolo commented Sep 6, 2023

Thank you so much for starting this PR to gather all the insights.

@ockham ockham mentioned this pull request Sep 28, 2023
16 tasks
@ockham ockham mentioned this pull request Mar 27, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants