Issue #3586438: Split scope display weight from subscription scoring weight
Description:
Splits the single weight attribute on AiContextScope into two independent parameters:
display_weight(ascending, lower = first) — controls form, tab, and listing order, matching Drupal#weightconvention.scoring_weight(nullable int) — controls subscription scoring influence independently of display order.
This MR adds:
AiContextScopeInterface: removesgetWeight(), addsgetDisplayWeight()andgetSubscriptionScoringWeight().AiContextScopeBase: both methods read a per-scope config override first, then fall back to the attribute value.AiContextScopeManager: removesgetScopePluginDisplayWeights();compareScopePluginOrder()now sorts ascending ongetDisplayWeight().AiContextScopeResolver: removes privategetSubscriptionScoringWeight()helper; calls$plugin->getSubscriptionScoringWeight()directly.- All 9 built-in scope plugins:
weight:renamed todisplay_weight:(10–90 range) plus explicitscoring_weight:where applicable. - Forms and deriver use
$plugin->getDisplayWeight()directly. AiContextScopeSettingsFormBase: adds Advanced section withdisplay_weightandscoring_weightoverrides; invalidateslocal_taskcache on save.- Config schema, test plugins, kernel/unit tests, and docs updated.
Testing Instructions
Prerequisites: A working Drupal 11 site with ai_context installed and at least one context item and one AI agent configured.
1. Verify scope display order (ascending)
- Go to any context item edit form.
- Confirm scopes appear in this order: Global → Use Case → Tag → Roles → Language → Site Section → Entity Type → Taxonomy → Specific Entities.
- Open
/admin/config/ai/context/settingsand confirm the Scope Settings tabs appear in the same order.
2. Verify the Advanced weight overrides
- Go to
/admin/config/ai/context/settings/scope/use-case. - Expand the Advanced section at the bottom.
- Enter
Display weight: 95andSubscription scoring weight: 200, then save. - Clear caches or wait for auto-invalidation — the Use Case tab should now appear near the end (between Taxonomy and Specific Entities).
- Revert the weight to
20and save again; the tab returns to its original position.
3. Verify scoring weight independence from display weight
- Configure an agent with a Use Case subscription set to a specific value.
- Set a context item with that Use Case value and confirm it appears as the top-ranked result.
- Lower the
scoring_weightfor Use Case to1via the Advanced section and confirm the item's relative scoring changes (it will score the same as a scope with default weight).
4. Verify no regression in tab cache
- After changing a display weight, navigate away and return — the tab order should persist without needing
drush cr.
Checklist
- I have updated the MR title to use format:
Issue #1234: My issue title. - I have updated the MR description to include:
Closes #1234 - I have performed a self-review of my own code
- I have added or updated tests, or explained in the description why this change is not covered by tests
- I have updated documentation for any new or changed functionality
- I have written testing instructions and verified them locally
- This MR contains no breaking API or hook changes, or they are explicitly documented in the description
Not applicable
- I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
AI Compliance
Note
Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.
- AI Assisted Code
Mainly written by a human; AI used for autocomplete or partial generation under full human supervision. - AI Generated Code
Mainly generated by AI, reviewed and approved by a human before this MR was created. - Vibe Coded
Generated by AI and only functionally reviewed before this MR was created.
Closes #3586438 (closed)
Edited by Kristen Pol