feat: #3633799 Offer Generate with AI inside each media type tab, as a switch next to Upload

Closes https://www.drupal.org/i/3633799

Depends on !29 (merged) (#3633789), which this branch includes; review that one first. After !29 (merged) merges this rebases to one commit.

What changed

  • "Where should the AI tabs appear?" (tab_position) gets a new default, inside: the Media Library tab list is core's (Image, SVG Image, Video, …), and each type with a generator starts with a switch, Upload | ✦ Generate with AI (with the "New" badge until Generate has been seen once).
  • Each mode has its own URL (ai_media=1); in the Media Library the switch swaps the content over AJAX like core's tabs and puts focus back on the chosen mode.
  • The same switch tops the Add media page (/media/add/{type}): Upload shows core's form only, Generate shows the generator in place of the upload widget. Generate media and the type chooser open Generate mode.
  • Standalone tabs stay: "As a tab of their own, right after…" (after_type) and "…after all the other tabs" (end).
  • Styled with the admin theme's variables (Default Admin's --admin-*, Gin's --gin-*), labels never wrap, focus ring, forced colors. The design follows a UX spec for Gin and Default Admin.
  • No update hook: pre-release, the default is in config/install.

Testing

  • Kernel: MediaLibraryAiTabsTest::testInside (tabs, switch, modes, no switch without generator or permission). Full suite: 86 tests pass; phpcs and phpstan clean.
  • Manually in Gin (Varbase 11): Media Library Image, SVG Image and Video; Upload ↔️ Generate; Add media page both modes; a real SVG generated in Generate mode; Generate media page and chooser links.

Screenshots

From a local Varbase 11 site in Gin.

Media Library, Image tab in Upload mode with the Upload | Generate with AI switch

Media Library, Image tab in Generate with AI mode

Media Library, SVG Image tab with the switch

Media Library, Video tab with the switch

Add Image page with the switch

AI-Generated: Yes

Checkpoints

  • Issue linked
  • Coding standards (phpcs, phpstan)
  • Automated tests
  • Tested manually in Gin
  • Tested manually in Default Admin
  • Docs: generating-media.md screenshots
  • Reviewed by a human
  • Code review by maintainers

🤖 Generated with Claude Code

Edited by Rajab Natshah

Merge request reports

Loading
Loading