2

Client has a custom Content Type for downloadable PDF document detail pages, which contains an entity reference to the File media type.

They want Full and Teaser view modes to display a thumbnail image, user-friendly title (not PDF filename), and link to download.

I added the field_media_image to the media file bundle, and I used the media file's Name field for the "friendly name" of the file.

The image and name could be edited by clicking the pencil icon on the image field to edit the media file directly, but it is a better user experience for content editors to edit the media file attributes from the detail page node, along with the rest of the document details.

If I change the field widget for the entity reference in the detail page's form display from Media library to Entity browser these fields are easy to edit from the detail page node by clicking the Edit button.

Clicking Edit in Entity browser widget allows users to easily update media file fields

This works well for editing existing content, but this widget is not configured correctly for uploading new PDF content:

Allowed types: png gif jpg jpeg.

There are some customizable widget settings in the form display configuration, but nothing that seems useful for my purposes.

The client is accustomed to uploading PDFs using the Media library widget, which looks like this:

Upload PDF by clicking "Add media" button

Unfortunately, the Media library widget does not allow user to edit fields on the media file bundle. This widget does not offer any customizable settings in the form display configuration.

Is it possible to write a small Drupal 8 module to use the Media library widget on this field if it is empty (or NULL), but use the Entity browser widget on this field if a PDF has been uploaded?

That would be ideal. If it's not possible, perhaps someone can help me to configure the Entity browser widget to behave more like the Media library widget for PDF uploads.

EDIT:

I think I might be on the right track:

Home >> Administration >> Configuration >> Content authoring >> Entity Browsers

I'm trying to add a new PDF Entity Browser. But when I use that, I get the following error message:

The entity must be of type media

What am I missing?

1 Answer 1

1

Going to Home >> Administration >> Configuration >> Content authoring >> Entity Browsers and creating a new entity browser is the right way actually.

But you probably have attached a media entity field to your content type therefore you must configure your new entity browser to be used on the media form display level.

Lets say your new entity browser is called Document browser you should go to the media form display for document media and make use of the new entity browser.

Here is a screenshot that might help understand better enter image description here

The content type form display widget for the respective field should remain as Media library in order to pick up the media library from previous step.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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