Use VariationCache for getAllComponentsKeyedBySource() cache context handling
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3573571. -->
Reported by: [scott falconer](https://www.drupal.org/user/52557)
Related to !606 !605
>>>
<p>CanvasAiPageBuilderHelper::getAllComponentsKeyedBySource() currently implements context-varied caching manually (custom cache ID building + direct cache.default reads/writes). This works, but duplicates logic already provided by Drupal core’s VariationCache and increases maintenance risk.</p>
<p>Background</p>
<p>- #3545477 introduced subrequests primarily for performance/caching concerns.<br>
- #3558241 removed subrequests due to form route-context regressions and replaced with direct controller call + manual caching.<br>
- The current result is correct functionally, but still has hand-rolled cache variation logic in Canvas AI.</p>
<p>Proposed resolution<br>
Refactor CanvasAiPageBuilderHelper caching to use VariationCacheInterface instead of manual CID/context logic.</p>
<p>Planned changes:</p>
<p>- Update modules/canvas_ai/src/CanvasAiPageBuilderHelper.php:<br>
- replace manual buildCacheId()/cacheBackend get/set flow with VariationCache get/set<br>
- keep current behavior and cacheability semantics<br>
- Update modules/canvas_ai/canvas_ai.services.yml:<br>
- inject variation cache service/factory-backed instance<br>
- Update modules/canvas_ai/tests/src/Kernel/CanvasAiPageBuilderHelperTest.php:<br>
- assert cache behavior (hit/invalidate/rebuild) instead of hardcoded backend cache IDs</p>
<p>Acceptance criteria</p>
<p> - getAllComponentsKeyedBySource() behavior is unchanged functionally<br>
- cache invalidation still happens correctly on component changes<br>
- no stale per-request data reuse regression<br>
- targeted canvas_ai phpcs/phpunit pass</p>
> Related issue: [Issue #3545477](https://www.drupal.org/node/3545477)
> Related issue: [Issue #3558241](https://www.drupal.org/node/3558241)
issue