feat: #3631526 Safety, AI Prompts, AI Context, animated SVG, video and editorial UX in one module

Issue: #3631526 "Initialize the AI Media module"

One MR for the work that was split over !8 (closed) to !19 (closed) (now closed in favour of this one). Built on 1.0.x after !6 (merged) merged; it started as one commit with the files of the !19 (closed) branch tip, and later work on #3631526 lands here as new commits.

What changed

  • Guardrail stops: when a site guardrail stops a call, AI Media shows the message, saves no file and writes no name, alt or title. Every call carries AI Media tags and one parent id per Generate press.
  • Moderation and errors: flagged prompts, a bad key and timeouts each get a clear message (admins see the fix).
  • Add media: /media/add/{AI type} shows the generator, so "Add media > AI-generated image" works. Drupal CMS's bulk-upload chooser completes a save.
  • Review step: one preview, with "Open full size in a new tab".
  • AI Prompts: generator and metadata prompts live in the AI module's prompt library; sites without the prompt config fall back to the shipped text.
  • AI Context: AI Media registers itself as an AI Context consumer type, with no submodule to enable: the plugin is found only when AI Context is enabled (1.0.0-rc1 or later), and its consumer type settings are optional config. Older AI Context releases keep working without site context.
  • Safety tab: pick one of the site's own guardrail sets. No rules of our own.
  • Generator form and settings: examples, disclosure, cost line, clearer Options; settings tabs reordered. Missing settings keys fall back to defaults at runtime (no update hooks).
  • "Generate media with AI" action on the media list.
  • Video is part of AI Media again, experimental and off by default (Enabled in the generators table turns it on) until the AI module supports a motion prompt (#3586540). No submodule: the ai_media_video submodule was folded in. Its Image to video provider row shows only while Video is on.
  • Media Library tab per generator: a new Media Library tab column in the generators table (generators.<id>.tab, on by default; a missing key counts as on). Off keeps the generator on core's Add media page and the "Generate media with AI" button, without a Media Library tab.
  • CI on Varbase 11: a new varbase-e2e-test job runs the same varbase-e2e suite on a fresh Varbase 11 site (drupal/varbase_project:~11.0.0, ImageMagick for its image toolkit, Varbase's form protection and login flood limits off for the robot), beside the Drupal core job; both share one hidden base job.
  • Documents are not part of AI Media. The document generator was taken out, so there is no dompdf or league/commonmark dependency. A generator from another module still plugs in the same way. The module, Composer and docs site descriptions say images, SVGs and videos, and the docs site no longer links the Documents page.
  • Animated SVG: the SVG generator can be static or animated (draw the strokes, CSS keyframes or SMIL), a Style option shown or hidden through Editor options (hidden, Static by default); each style's prompt is an AI Prompt. A new ai_media:animated-svg component prints sanitized SVG inline, starts the motion when it scrolls into view, staggers the parts, honours reduced motion and takes an accessible label; it needs no AI and Canvas can place it. The "Inline SVG (animated)" display and the review preview use it. A stricter SvgSanitizer builds on enshrined/svg-sanitize and allows only what animation needs. An answer must draw (3 or more drawable elements, complete path data), CSS-animated transforms move onto a wrapper, refused answers are retried up to 3 times within the AI module's request timeout, and a timeout names the provider, model and seconds. While the SVG generator is on, SVG media can be selected (media thumbnail accepts svg) and shows through image styles. Adds the allowMediaEmbedTypes config action, generic example SVGs and recipes/ai_media_svg_example. A CKEditor "Generate SVG" button is not added: CKEditor 5 cannot hold inline SVG.
  • Figma is not part of AI Media for now. The ai_media_figma submodule and the two hooks it used (hook_ai_media_generate_fields_alter(), hook_ai_media_prompt_context()) were taken out; drupal/ai_figma is no longer a require-dev or suggest.
  • Docs: AI integration page, README hero image, and current screenshots on the SVG page (SVG review), Media types and generators (core's Add media page) and Settings (Safety tab).
  • Requires drupal/ai ^1.5. Labels are now "AI-generated image/SVG/video".

Tested

  • Claro, Gin and Default Admin at 1440 and 1920; axe 0 WCAG 2.2 AA violations.
  • Kernel tests (guardrail stops for image, SVG and Ask AI) and the Varbase E2E suite; all pipelines green on the stacked branches.
  • Animated SVG on a plain Drupal 11 site: the style option and preview in Claro, Gin and Default Admin at 1440 and 1920; the example recipe page (draw and CSS keyframes) animating on scroll, with screenshots before and after; reduced motion showing the finished drawing; 12 SVGs from an earlier, unpublished project run through the sanitizer, the quality check and the component (all kept, all drawn); Kernel tests for the sanitizer (hostile and animation cases), the quality check and retries with scripted replies, the timeout message, SVG media selection and image styles.
  • Real OpenAI and Anthropic results on Varbase 11 for the screenshots (3 paid calls).
  • Docs: cspell 0 issues, and every page in the mkdocs.yml menu exists.
  • AI Context folded into AI Media: 63 Kernel tests pass on Drupal 11 with AI Context 1.0.0-rc1, the consumer type test among them; phpcs and cspell clean. The consumer type API is the same in AI Context 1.0.0-beta5, and 1.0.0-beta4 has no consumer types, so it never loads the plugin.
  • Figma taken out: 63 Kernel tests pass; phpcs and cspell clean; no Figma or hook mention left in the code or docs.
  • Video folded in, with the tab setting: 67 Kernel tests pass (video off by default, offered without a tab, an older site without the key keeps its tabs, consumer types include video); phpcs and cspell clean; a new E2E scenario checks a generator without a tab still works on Add media.
  • Pipeline 1014954 green: functional-testing (Drupal core) and varbase-e2e-test each pass all 41 scenarios. On the way, the Media Library tab checkbox stopped being disabled while its generator is off: a disabled checkbox is not posted, so a save could switch the tab off.

Not tested

  • Real image-to-video and moderation providers.
  • A screen reader pass (keyboard order and the accessibility tree were checked).
  • Mobile widths.
  • Animated SVG from a real model (Echo cannot draw; Kernel tests script the replies), on Drupal CMS and Varbase, in Safari, and with SMIL in Firefox.

AI-Generated: Yes. Drafted and tested with Claude Code, reviewed by the maintainer.

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