Loading
feat: #3631526 Register AI Media as an AI Context consumer type
Issue: #3631526 "Initialize the AI Media module"
Chunk 6 of the UX and integration plan (20 October 2026): the AI Context consumer type (plan section 2.4).
Depends on !12 (closed) (3631526-ai-prompts), which depends on !11 (closed), !10 (closed), !9 (closed), !8 (closed) and !6 (merged). Until those merge, this diff includes them; the change of this MR is its last commit.
What changed
- New submodule AI Media Context (
modules/ai_media_context), withai_context:ai_context (>=1.0.0-rc1)in its info file, as AI Context's consumer API docs recommend for a module that is not an agent. It shipsai_context.consumer_type_settings.ai_media(enabled: true) and its schema. - Consumer type plugin
ai_media:- instances from the generator plugins (
ai_media:image,:svg,:video,:document) plusai_media:metadata_name,:metadata_alt,:metadata_title; getRoutingRequestTags()returns['ai_media'];resolveConsumerId()claims a request only with exactly oneai_media_metadata:<target>tag, else exactly one knownai_media_generator:<id>tag (an "Ask AI" request carries both, the metadata tag decides); AI Media's own "Use site context" off declines every request;getLabelRoute()points to the AI Media settings; instance defaultpush_enabled: TRUE, since context was on by default in AI Media.
- instances from the generator plugins (
- Chat requests (SVG, document, Ask AI): AI Media no longer appends context to the prompt. It sends the
entity_contextrequest metadata (from !8 (closed)) and AI Context's push subscriber puts the context in the system prompt. - Image requests (image, video frame) are not chat, so AI Media pulls with the generator's consumer ID (
getResult([], NULL, $entity, 'ai_media:image')) and puts the rendered context in the{context}variable of the image AI Prompt (from !12 (closed)). Nothing of AI Media's own wording is added. - Removed from AI Media: its own scope lists (
working_with_media, language), its token limit, and the per-generator and per-target lists. Theai_mediause case scope value stays. Settings keep onlyai_context.enabled, now "Use site context from Context Control Center", with a link to the CCC consumers. The tab is renamed "Site context" and says what is missing when AI Context, its version or the submodule is. - Editor line: "Uses site context: N items" for an image (the pull), "Uses site context." for a chat generator, and "Used site context." on the result when AI Context reports a push or the pull found items. Never the items.
- No update hook and no post update, by the maintainer's decision while the module is initialized: the removed keys go from
config/installand the schema only. A site that installed an earlier commit keeps the old keys until the settings form is saved. composer.json:drupal/ai_contextinrequire-dev(for the CI Kernel test) and insuggest.
How it was tested
- Kernel
AiMediaConsumerTypeTest(submodule): instances, routing (single generator, metadata over generator, none, two generators, unknown generator, AI Media switch off), a document request gets the item pushed (contextUsed() === 1) with nothing added to the user message, an image request gets the item in its prompt through the pull, and off sends the description alone. All 24 Kernel tests of the module pass. - Plain Drupal 11.4 (
aimplan1) with AI Context 1.0.0-rc1 and ai_agents, one global published item: document and image generation report 1 context item; off reports none; the CCC consumers list shows the AI Media consumers; usage tracking records the pushed document request underai_media:document. - axe-core 4.10.2: 0 violations on the Site context tab and on the image generator with the context line and the result, in Claro, Gin and Default Admin at 1440 and 1920.
- Varbase E2E free lane, Firefox: see the pipeline (the CI site has no AI Context; the tab shows its note).
- phpcs (Drupal, DrupalPractice), phpstan level 1, cspell, eslint, stylelint: clean.
Not tested
- AI Context records usage for pushed requests only: the image pulls are not in the usage list in 1.0.0-rc1, and AI Media does not call AI Context's internal usage tracker.
- The "needs 1.0.0-rc1" note with an AI Context beta: not reinstalled here (the message is unchanged from !6 (merged)).
- Real providers (Echo only).
- Mobile widths (out of scope).
AI-Generated: Yes. Written with Claude Code (Claude Opus 5.5) under the Drupal AI policy; tested by the author before submission.
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