Skip to content

Port the Lead Image block sidebar to BlockDataForm - #8473

Open
sneridagh wants to merge 4 commits into
claude/core-blocks-blockschema-69ed0efrom
claude/leadimage-sidebar-blockdataform
Open

sneridagh wants to merge 4 commits into
claude/core-blocks-blockschema-69ed0efrom
claude/leadimage-sidebar-blockdataform

Conversation

@sneridagh

Copy link
Copy Markdown
Member

Stacked on #8472: this PR targets that branch, so the diff only shows the sidebar port. Merge #8472 first; GitHub then retargets this PR to main.

#8472 gave the leadimage block a blockSchema (align, href, openLinkInNewTab) but left LeadImageSidebar as a hand-built form with legacy widgets, so the editor and the config were two separate sources. This PR ports the sidebar to BlockDataForm.

What changed

  • LeadImageSidebar reads the schema from blocksConfig[data['@type']].blockSchema (falling back to LeadImageBlockSchema), the same way ImageSidebar and MapsSidebar do after Add a blockSchema to the image, maps, toc, html and leadimage core blocks #8472. Add-ons can now change the lead image sidebar through the block config, and schemaEnhancers apply.
  • The alt text is not block data: it is the content item's image_caption field. The sidebar adds it as the first field of the form, shows the content value, and routes its changes to onChangeField (content) instead of onChangeBlock.
  • BlockDataForm calls onChangeBlock with the whole form data when it mounts, so the sidebar strips content fields before writing the block. If an older block already stored an image_caption in its data (the block view still falls back to it), that value is kept as is.
  • The stored data shape is unchanged: href uses the url widget, which stores a flattened URL string like the old text field did.
  • The header, the image preview and the "no image" state are unchanged.

Editor look

The fields are now rendered by the standard block form, so the sidebar looks like the Image block sidebar: alt text and alignment in the default fieldset, then a "Link settings" accordion with "Link to" (URL field with the object browser button) and "Open in a new tab". Before, the same fields were laid out by hand in a similar order.

Locales

pnpm i18n drops three message IDs that the old sidebar defined but never rendered: Origin, External URL and No image set in image content field. The other locale changes are source-reference updates.

Tests

  • LeadImageSidebar.test.jsx now mocks BlockDataForm and checks that the form gets the block schema plus the alt text field, that alt text changes go to the content and other changes to the block, that content fields stay out of the block data (and a legacy image_caption in the block data is preserved), and that no form renders without a lead image. The snapshot changed because the hand-built widgets are replaced by the form; that change is intended.
  • I checked it manually in a local dev site (Volto from this branch on a local Plone backend). The local site's types have no lead image field, so the editor's content response was patched in the browser to include an image. Alt text, alignment, link and new-tab changes all applied in the editor. After saving, the block data held only @type, align, href and openLinkInNewTab. Alt text persistence itself could not be checked there, since that site has no image_caption field.

The sidebar now renders the leadimage blockSchema read from the block
configuration, plus the alt text field, which is stored in the content
item's image_caption field and kept out of the block data.
…image-sidebar-blockdataform

* claude/core-blocks-blockschema-69ed0e:
  Fix saving a type layout with blocks that have a blockSchema
…image-sidebar-blockdataform

* claude/core-blocks-blockschema-69ed0e:
  Add a Form test for submitting blocks with a blockSchema without content

@davisagli davisagli left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with the lead image behavior from plone.app.contenttypes. Works. (The alt text was kept in sync with image_caption in the content data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants