fix: #3621159 Seed the AI Context items through AiContextItem::setScope()

Issue: https://www.drupal.org/i/3621159

What

VarbaseAiFigmaInstaller::seedOwnContextItems() wrote the grouped scope array (['global' => ['global']], from ai_figma.settings:context_scope) straight into the ai_context_item scope field, in two places: on the update path via set('scope', ...) and on the create path via create([... 'scope' => ...]).

AI Context 1.0.0-beta5 (https://www.drupal.org/i/3586405) replaced that scope map field with a multi-value scope_id + value field, so both paths now throw:

InvalidArgumentException: The scope field accepts only Field API deltas (scope_id + value). Use AiContextItem::setScope() for grouped arrays of scope_id => [value, ...].

The exception is caught and logged, so the recipe still reports success while the context items are never created.

Why this shape

  • AiContextItem::setScope() takes the grouped array on 1.0.0-beta4 as well as on 1.0.0-beta5, so the fix works either side of the BC break and drupal/ai_context: ^1.0 needs no change.
  • create() routes the value through the same field setter, so scope is set on the entity after create() rather than passed into it.
  • The method_exists() guard matches the existing style in the same method and keeps an older AI Context without setScope() working.

Verified

  • php -l clean.
  • PHPCS with the Drupal and DrupalPractice standards: 0 errors, 0 warnings on the changed file.
  • The AiContextScopeItemList and AiContextItem::setScope() sources of ai_context 1.0.0-beta5 and 1.0.0-beta4 were read to confirm the method name, signature and the grouped-array contract.

Not verified here: a full install run on a site resolving ai_context 1.0.0-beta5. The pipeline on this MR covers the rest.

Varbase AI Figma Base carries no PHP of its own and needs no code change; it will need a follow-up release once this is released so its dependency resolves to a working version.

AI-Generated: Yes

Checkpoints:

  • File an issue
  • Addition/Change/Update/Fix
  • Testing to ensure no regression
  • Automated unit testing coverage
  • Automated functional testing coverage
  • UX/UI designer responsibilities
  • Readability
  • Accessibility
  • Performance
  • Security
  • Developer Documentation
  • User Guide Documentation
  • Reviewed by human
  • Code review by maintainers
  • Full testing and approval
  • Credit contributors
  • Review with the product owner
  • Release notes snippet
  • Release
Edited by Rajab Natshah

Merge request reports

Loading
Loading