I have a multiple-value entity reference field with target type = media. It is used for "document" media, so mostly pdf files.

I am using the "Media library" widget shipped with core. With this widget, items appear in a grid with thumbnail, and can be reordered with drag + drop.


Most of the pdf files don't have a useful thumbnail, so they all look the same.

Due to the grid display, the title of each document is not fully visible.

The grid drag + drop reorder is less intuitive than a tabledrag, especially if the thumbnails all look the same, and sometimes even the visible part of the title is the same.

Once a media entity is added to the list, there is no link to edit this media entity from the node / host entity form.


Is there a table version of the media library widget?

Is there a way to show an edit link with each item? Either to edit the media in a form on a new page, or in a popup.

What I tried

Widget settings?
-> The widget does not have any settings.

Configure the display of documents in "Core | Media library" view mode?
-> Items still displayed in a grid.
-> The only field that looks well in a grid mode is the thumbnail. Text fields look weird.


Poor soul who asked the same in drupal.org, with no success: https://www.drupal.org/forum/support/module-development-and-code-questions/2020-06-29/how-set-media-library-widget-to

  • I added Media Entity Browser for this reason. It will bring back the edit dialog when double clicking a media item. – Kevin Feb 21 at 23:47
  • I ended up making a subclass of core MediaLibraryWidget. It was enough to override formElement() and preRenderWidget() to do some custom modifications. I replaced the 'selection' with a '#theme' => 'table' with tabledrag, similar to template_preprocess_field_multiple_value_form(). I might publish this, and then post an answer. – donquixote Feb 22 at 22:05
  • I also tried "Entity Browser", but it seemed I need too many modules to achieve the desired result. – donquixote Feb 22 at 22:05

In response to your second question, there is a core issue open regarding editing media items within the field widget: https://www.drupal.org/project/drupal/issues/2985168

There is also a contrib module Media Library Edit.

One problem is that you will edit the media entity itself, affecting all usages of the media item.

  • It should not be an issue though because someone should understand that media items are references. – Kevin Feb 21 at 23:47
  • @Kevin Site builders would know this but it can be confusing for end users who just want to manage the content on their website. – imclean Feb 22 at 3:59
  • I tried the media library edit, but it looks a bit awkward without a table display :) – donquixote Feb 22 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.