Loading
fix: #3633061 Show the AI tab when a field allows only one media type
Issue: #3633061
Follow-up to !22 (merged). Core's Media Library shows no tab menu when a field allows only one media type, so a field such as Varbase's blog or page Featured image, which allows only Image, had no Generate image with AI tab: the library opened straight on the upload form. With several types (CKEditor Insert Media) the tabs were already right.
What changed
AiMediaLibraryUiBuilder::buildMediaTypeMenu()builds the menu for a single allowed type when that type has an AI tab for the current user, the same link core builds for each type. The menu hook then adds the AI tab, so the library shows Image | Generate image with AI. Without an AI tab it stays as core: no menu.- The tab rules (tabs on, generator offered and shown as a tab, permission, configured or an administrator) are now one method,
AiMediaGeneration::tabShown(), used by the builder and the menu hook. - Docs: one line in Media types and generators.
Tested
- New Kernel test
MediaLibraryAiTabsTest::testSingleType: Image only gives Image and Generate image with AI, with the right active tab in both modes; no menu for a type without a generator, with its tab setting off, or without the permission. 81 Kernel tests pass locally on Drupal 11.4.11. - The fixtures recipe adds a Featured media field on Article that allows Image only, and
03-01-01-access-controlhas a scenario for it: the two tabs, and the AI tab opening the generator. Run locally on a fresh Drupal 11.4 standard site with the Echo provider. - phpcs (Drupal, DrupalPractice) clean; phpstan level 0 shows only the
new static()notices the template ignores.
AI-Generated: Yes. Drafted and tested with Claude Code.
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
- Documentation
- Reviewed by a human
- Code review by maintainers
- Full testing and approval
- Credit contributors
- Review with the product owner
- Release notes snippet
- Release
Edited by Rajab Natshah