Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides a reusable form element that allows users to select media from the Media Library. It can be integrated into various Drupal forms, such as those in Paragraphs behaviors, Layout Builder, or configuration settings.

This module provides a Form API element to select a Media entity from the Media Library. This element can be used in all standalone forms. I'm currently using this in a Paragraphs behavior form to select a background image with crop-support, but you can use it in a Layout builder form, or a configuration form under "Settings"...

The implementation is borrowed from the Media Library widget and follows its user interface as well as its possibilities:

  • You can limit the allowed media types by passing the machine names of those media types
  • The default value is either:
    • Empty: NULL
    • a single Media entity's ID: (int) 1
    • multiple Media entity ID's separated by comma as a string: (string) 1,2,3,4
$form['image'] = [
  '#type' => 'media_library',
  '#allowed_bundles' => ['image'],
  '#title' => t('Upload your image'),
  '#default_value' => NULL|1|'1,2,3',
  '#description' => t('Upload or select your profile image.'),
];

I chose to release this as a standalone module so anyone can review / contribute / fork / ... without having to wait on the official core patch (https://www.drupal.org/project/drupal/issues/3065677).

Feel free to test-drive, suggest improvements or post bug reports should you encounter any!

All features have been implemented thus far, so if anyone lacks something, feel free to create an issue!

Activity

Total releases
3
First release
Jul 2025
Latest release
9 months ago
Releases (12 mo)
2 ▲ from 1
Maintenance
Slowing

Release Timeline

Releases

Version Type Release date
2.1.4 Stable Sep 30, 2025
2.1.3 Stable Sep 26, 2025
2.1.2 Stable Jul 4, 2025