Define how block settings should be presented in the UI

Created on 30 October 2024, about 2 months ago

Overview

Some blocks can be configured via block settings when placed into a page. We have at least two options for presenting the block settings to the user:

1. Use the settings form via the ::blockForm() method on the block plugin.

Pros: UI is the same as the existing Drupal block UI
Cons: Will this always work inside React? What if we want to map field values to block settings? (see πŸ“Œ Define `props` in the context of Block components Active )

2. Use the block config schema to build a settings form

Pros: Autogenerated forms will be easier to handle in the client
Cons: What if ::blockForm() allows dynamic values or uses other advanced features of forms?

One possible idea is to converge these two options: for fully validatable blocks, allow the block plugin to opt out of providing a form, and automatically generate it from the config schema instead. Then the Drupal core block UI will use same automatic form layout as the XB UI will use, but on the XB side we can augment the form elements if we need to (e.g. to provide dynamic field mappings).

Proposed resolution

?

User interface changes

πŸ“Œ Task
Status

Active

Version

0.0

Component

Config management

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @longwave
  • πŸ‡¬πŸ‡§United Kingdom longwave UK
  • πŸ‡¬πŸ‡§United Kingdom longwave UK
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Cons: Will this always work inside React?

    I don't see why not? I'd like to see @bnjmnm comment on this aspect.

    Cons: What if we want to map field values to block settings? (see πŸ“Œ Define `props` in the context of Block components Active )

    ℹ️ I'm assuming that by , you mean DynamicPropSources aka product requirement 7.1 Token.

    Why would that make sense? Isn't that what Block plugins already have the context functionality for? This sounds like it'd be a confusing duplication of that functionality. IMHO we should limit

    2. Use the block config schema to build a settings form

    Pros: Autogenerated forms will be easier to handle in the client
    Cons: What if ::blockForm() allows dynamic values or uses other advanced features of forms?

    This cannot work AFAICT.

    See my detailed write-up at #3462241-8: [PP-1] Decorate the SDC plugin manager and allow components defined in code β†’

    One possible idea is to converge these two options: for fully validatable blocks, allow the block plugin to opt out of providing a form, and automatically generate it from the config schema instead.

    Interesting idea! πŸ€” But … config schema is not rich enough in its metadata to convey everything. Lots of validation constraints use logic to define valid values, conditional values, and so on.

    Hence it sadly follows that it's impossible to auto-generate equivalent forms from a fully validatable block plugin's config schema! 🫀

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Is there a third option somewhere in the middle here where some components are flagged (e.g. via hook_block_alter for blocks) as being 'simple' in so far as keys in ::blockForm map 1:1 to their settings. Even if they're not fully validatable.
    For these we can call ::blockForm and make use of the existing FormState react functionality to keep the store in sync.
    For items that we review and determine that there's more going on in ::blockSubmit ::blockValidate we make a round-trip back to the server to resolve props from form values.
    I think there's going to be enough use cases for something like this that we can make it generic on the Component config entity, i.e. the UI should be simple and not need to know the difference between blocks and SDC and anything else added later, it should just know that some components need a round trip to Drupal to transform form values into settings/props - whilst others don't. There are cases where we will need this for field widgets (e.g. ::massageFormValues) and places we will need it for SDC (think Media widget where we resolve an image URL via a hard-coded attributes approach atm).
    Thoughts?

Production build 0.71.5 2024