Media library extra form widget is not working with gallery media

Created on 4 October 2024, 3 months ago

Problem/Motivation

We want the widget for gallery media field work like the ones for images and video: Allow to select existing galleries or create a new on using the media library extra form for media field on gallery paragraph.

Steps to reproduce

In thunder 7.3 Entity Embed was replaced by the core Media Library. Upgrading to 7.3 we also did that switch, uninstalled and removed entity embed module. Using the thunder demo installation: Under /admin/structure/paragraphs_type/gallery/form-display we enabled the widget "Media library extra" and configured it the same way as for image or video paragraph. On clicking the "select media" button the media library view appears but not the form to create a new gallery.

BTW: We have many similar media entities, which we would like to add the same way. In most cases there is no way to crate new media entities. In other cases the upload widget appears, although it's not clear why/how it works, but not the other form fields.

How could it be achieved?

💬 Support request
Status

Active

Version

7.3

Component

Code

Created by

🇩🇪Germany osopolar 🇩🇪 GER 🌐

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @osopolar
  • 🇩🇪Germany osopolar 🇩🇪 GER 🌐

    I already found a hint to my issue, see hook_media_source_info_alter() in media_library.module (media_library_media_source_info_alter()): the form to create media entities got added there for some types. For the slideshow plugin (docroot/modules/contrib/media_entity_slideshow/src/Plugin/media/Source/Slideshow.php) the media_library_add is not defined. Therefore \Drupal\media_library\MediaLibraryUiBuilder::buildMediaTypeAddForm() returns an empty array:

    if (empty($plugin_definition['forms']['media_library_add'])) {
      return [];
    }
    

    Therefore the next step would be to add "add forms" for the other media plugins.

  • 🇩🇪Germany osopolar 🇩🇪 GER 🌐

    I have found how it might work: Add the media_library_add form to source info using hook_media_source_info_alter():

    /**
     * Implements hook_media_source_info_alter().
     */
    function custom_module_media_source_info_alter(array &$sources) {
      if (empty($sources['podcast']['forms']['media_library_add'])) {
        $sources['podcast']['forms']['media_library_add'] = MediaNameForm::class;
      }
    }
    

    And then implement the form, see for example docroot/core/modules/media_library/src/Form/OEmbedForm.php

  • 🇩🇪Germany osopolar 🇩🇪 GER 🌐
Production build 0.71.5 2024