fix: #3620603 Fail safely when Canvas ships ComponentTreeLoader as final

Closes #3620603.

On an unpatched Canvas the module took the whole site down. CanvasOverrideComponentTreeLoader extends Drupal\canvas\Storage\ComponentTreeLoader, which Canvas ships as final, and subclassing a final class is a PHP fatal raised the moment the subclass loads. Every page died, /user/login and /admin/modules included, and drush could not bootstrap, so the module could not be switched off through the UI.

What this does

  • The service swap now reflects on Canvas's own class and skips itself when that class is final. ::class is a compile-time constant and does not autoload, so on an unpatched Canvas our subclass is never loaded and no fatal can occur.
  • A container parameter records whether the swap happened.
  • The content type form explains why the feature is unavailable and disables the checkbox, so nobody saves a setting that does nothing.

The warning is deliberately on the content type form rather than in hook_requirements. It belongs where someone is switching the feature on, not on every site's status report.

What this does not do

It does not remove the Canvas patch requirement. Per-content layouts still need the Canvas patch listed on the Canvas Override project page, which comes from #3567225. Upstream declined to make ComponentTreeLoader extensible (canvas!948 (closed), closed 10 August 2026) on the grounds that per-node component trees are a planned first-class feature and that swapping the loader would create an accidental API. Canvas 1.10.1 still ships the class final with both constructor properties private readonly.

So this change turns a site-wide fatal into a clear, contained message. Making the feature work without the patch depends on upstream.

AI usage: prepared with assistance from Claude Code (Anthropic), reviewed by Rajab Natshah, per https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquette/policy-on-the-use-of-ai-when-contributing-to-drupal

Checkpoints

  • File an issue
  • Addition/Change/Update/Fix
  • Testing to ensure no regression
  • Automated unit/functional testing coverage
  • Developer Documentation support
  • User Guide Documentation support
  • 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