Problem/Motivation
The ai_context_item content entity provided by the AI Context (Context Control Center) module stores its scope (Global, Use Cases, Tags, Site Sections,
Entity Bundles, Target Entities, Languages) in a map base field with arbitrary keys.
Drupal core's \Drupal\Core\DefaultContent\Importer calls $item->get($property_name) for every key found in a field's YAML payload. MapItem::propertyDefinitions() returns an empty
array, so get() throws "Property is unknown." as soon as the YAML contains anything other than an empty map.
The inverse direction is also broken: drush content:export ai_context_item N normalises the map field to scope: - { } even when the entity has {"global":["global"]} stored in the
database.
The consequence is that recipes that ship content/ai_context_item/*.yml files (for example Varbase AI Context) cannot pre-populate the scope.
Every imported item lands with an empty scope, no agent picks it up at runtime, and the operator must edit each item by hand after applying the recipe — defeating the purpose of shipping starter context items.
Proposed resolution
Add a new config action plugin setAiContextItemsDefaultScope to the varbase_recipes module that lets recipes assign a scope to imported ai_context_item entities in pure YAML, without
shipping the scope through the content import path.
Design:
- The action attaches to one of the
ai_context.scope_settings.*config objects shipped by theai_contextmodule — for exampleai_context.scope_settings.globalor
ai_context.scope_settings.use_case. The scope plugin id is derived from the segment after the prefix. - Recipes pass an array of scope values as the action value.
- Because Drupal recipes run config actions before the content step, the action's
apply()registers an in-process listener onRecipeAppliedEvent. The listener fires after content import has
finished, loads everyai_context_itemwhose scope is still empty, and writes[scope_id => values]via\Drupal\ai_context\Entity\AiContextItem::setScopeValues(). - Items that already carry a scope are skipped, so the action is idempotent and re-applying the recipe is safe.
Example — apply Global scope to all imported items:
config:
actions:
ai_context.scope_settings.global:
setAiContextItemsDefaultScope:
- global
Example — apply a Use Case scope:
config:
actions:
ai_context.scope_settings.use_case:
setAiContextItemsDefaultScope:
- writing_words
- working_in_canvas
Remaining tasks
- ✅ 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
- ✅ Code review from 1 Varbase core team member
- ✅ Full testing and approval
- ✅ Credit contributors
- ✅ Review with the product owner
- ✅ Update Release Notes
- ❌ Release varbase-11.0.0-beta1, varbase_starter-beta1, varbase_recipes-1.0.0-beta1
User interface changes
- N/A
API changes
- N/A
Data model changes
- N/A
Release notes snippet
- fix: #3589734 Add
setAiContextItemsDefaultScopeconfig action to apply scope values to imported AI Context items
Comments
Comment #3
rajab natshahComment #4
rajab natshahComment #6
rajab natshahComment #7
rajab natshah✅ Released varbase_recipes-1.0.0-beta1
Comment #9
rajab natshah✅ Released varbase-11.0.0-beta1