feat: #3631526 Generate on core's Add media page instead of a file upload

Issue: #3631526 "Initialize the AI Media module"

Chunk 3 of the UX and integration plan (20 October 2026): the generator on core's /media/add/{ai type} (plan section 3, option (a)).

Depends on !9 (closed) (3631526-moderation-errors), which depends on !8 (closed) and !6 (merged). Until those merge, this diff includes them; the change of this MR is its last commit.

What changed

  • Core's Add media page for an AI media type no longer shows "Choose File". A media_form alter (AiMediaAddPage) puts the generator in place of the upload: Description, Options, Generate (core HTMX, same as the tab). The result fills the source field, the name and the alternative text; core's own Save keeps it. "Generate again" replaces the unsaved file. Nothing is saved before Save. Before a result there is no file field, no name and no Save.
  • Without Generate media with AI, or when the generator is not offered or not set up: one sentence and no form (administrators get the "not set up" message with the settings link). Core's create access still decides who opens the page.
  • Errors from Generate show inside the form (the swapped part), are announced assertively and focus the description.
  • The description, options, format check and the Generate press move out of the Media Library form into an ai_media.generation service, so the tab and the page share them. The Media Library tab behaves as before.
  • Test fixtures and docs: media type labels become "AI-generated image", "AI-generated SVG", "AI-generated document" (they read well where core makes a label plural, the bulk-upload "…with AIs" title). The Media author fixture role may create AI images without the AI permission, to test the sentence. New 09-01-01-media-add.feature.
  • No new route, menu item or permission.

How it was tested

  • Plain Drupal 11.4 site (aimplan1), Echo provider, headless Firefox:
    • Content editor: /media/add/ai_image shows no file input and no Save; Generate fills name and alt, focus moves to the name; Generate again replaces it (the earlier temporary file is deleted); Save creates the media item and the file becomes permanent. Same for a PDF document, with its preview and link.
    • A user with "create ai_image media" but not "Generate media with AI": "You do not have permission to generate media with AI." and no form.
    • Text-to-image provider removed: editors read the "not set up yet" sentence, administrators the message with the settings link.
    • A guardrail stop on Generate shows the message inside the form.
  • axe-core 4.10.2 (WCAG 2.0, 2.1 and 2.2 A and AA): 0 violations on the empty form, the generated image, the error state and the generated document, in Claro, Gin and Default Admin at 1440 and 1920.
  • Drupal CMS 2 site (aimcms1, ai 1.5.1) with this branch: Content > Media > Add media goes to the bulk-upload chooser; choosing the AI image type opens the generator (no file input); Generate then Save created the media item. Run as a scripted Playwright flow, not as a suite feature (the module's suite runs on standard Drupal, which has no bulk upload).
  • Varbase E2E free lane, Firefox: 40 scenarios, 752 steps passed (all features, including the new one).
  • Kernel tests (15) pass. phpcs (Drupal, DrupalPractice), phpstan level 1, cspell, eslint, stylelint: clean.

Not tested

  • The bulk-upload chooser path as a suite feature in CI (scripted run on Drupal CMS only).
  • SVG and video on the Add media page (same code path as image; no video provider).
  • The Drupal CMS site's own media type labels still read "…with AIs" there: they are that site's configuration, not changed here.
  • 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

Merge request reports

Loading
Loading