fix: #3621557 Let a node act as its own Canvas host entity so component props save

Issue: https://www.drupal.org/project/canvas_override/issues/3621557

Problem

Changing any prop on a component that Canvas Override seeded from the content type's ContentTemplate fails:

PATCH /canvas/api/v0/layout/node/{node}  ->  HTTP 500
InvalidArgumentException: A host entity is required to set entity field prop sources.

Canvas resolves the host entity from the route's preview_entity, which only exists on the ContentTemplate routes; a node's own tree passes NULL. Seeded components carry entity-field bindings to the node's fields, so this hits nearly every component — even changing an unrelated prop like the heading level fails and the edit is silently lost.

Resolution

For a per-content layout the host entity is the node itself. A request subscriber sets the node as the preview_entity attribute for canvas.api.* requests on canvas_override-enabled nodes. No Canvas patch involved: those paths ignore the preview entity when rendering a fieldable entity's own tree, and the only assert(is_null($preview_entity)) is on the config-entity (pattern) branch, which a node never reaches. A real ContentTemplate preview entity is never overridden.

Verification (Varbase 11, Drupal 11.4.6, Canvas 1.10.1)

Case Before After
Change heading level on the title-bound seeded component PATCH 500 PATCH 200
Publish it lost published and persisted
Stored input — level: 2 with the entity-field binding to node:blog › title intact
Plain canvas_page (control) 200 200, unchanged

Not a JS error — the console showed only cosmetic upstream SVG warnings. phpcs clean; 12 PHPUnit unit tests pass.

AI-Generated: Yes (investigated and authored with Claude Code; reviewed by Rajab Natshah.)

Checkpoints

  • File an issue about this project
  • Addition/Change/Update/Fix to this project
  • Testing to ensure no regression
  • Automated unit/functional testing coverage
  • Developer Documentation support on feature change/addition
  • User Guide Documentation support on feature change/addition
  • UX/UI designer responsibilities
  • Accessibility and Readability
  • Reviewed by a human
  • Code review by maintainers
  • Full testing and approval
  • Credit contributors
  • Review with the product owner
  • Update Release Notes
  • Release
Edited by Rajab Natshah

Merge request reports

Loading
Loading