1

In Drupal 8, I created a new Media type "PDF Files." I have imported almost 30,000 of them, each complete with Title (Name), file, and the taxonomy that categorizes them.

On the content type (Let's say the default Article, for example) I've added an entity reference field and the ability to locate a file via the Entity File Browser project (https://www.drupal.org/project/entity_browser).

This is working well enough, but it searched via the Name field only by default.

How can I accomplish the same thing but searching by comma separated tags?

So, each file has a tag structure TAG1, TAG2, TAG3.

In the search field for the file while in the content type, if I type in TAG1, TAG3 then all the files with that combination of tags should come up.

Before I dive into a custom script or extending the entity browser, wanted to make sure this isn't something simple I'm overlooking. (Just now getting into D8 after a long D7 background).

UPDATES:

So as has been suggested in the comments, use a view as a reference. It seems that choosing a view reference requires that the view be an Entity Reference (instead of type Page, Block, etc.) But, it seems that Media doesn't have the ability to search by tag. This Drupal project seems to try to address that - https://www.drupal.org/project/media_taxonomy_filter but no luck.

Also, another hurdle I seem to have hit is that when creating a View of type Media, there is no taxonomy field filter. This seems odd in that Media now can be categorized with taxonomy. Is that right? Like, for the admin media page which is powered by a view, can I not filter that by taxonomy?

  • Can't entity browser be powered by a view result w filters? Have you tried making a new View? – Kevin Jan 10 at 18:32
  • Wow, that's an option? You mean, just like I would create an exposed filter for the front end, I can achieve the same as part of the node (content) edit form? – blue928 Jan 10 at 19:47
  • I thought you meant the Entity Browser embed tool... I think you can create a View and configure a new embed dialog from the admin. – Kevin Jan 10 at 19:50
2
+100

As Kevin said, you need to install the Entity browser module

Optional module: I personally also use Entity Browser Enhance(d|r) for a much better usability when selecting media.

Go to /admin/structure/views/add and create a view showing Media items. On the next screen add a display type Entity browser to your view. You must add the special Entity browser bulk select form field to this view. Configure the view with additional fields and filters of your own choice. E.g. if you need taxonomy tags, add an exposed filter for your tags field.

Under Configurarion > Content Authoring > Entity browsers, create a new entity browser for your media. Configure as you need, and in the last step add the previously created view as widget plugin.
(Beyond the selection view you could add multiple widgets here like DropZoneJs for in-place uploading or Inline Entity form for in-place creating of new nodes).

Go to Structure > Content Types, and edit the form display of your node. Change the widget of the media field to Entity browser and select your previously created browser.

There are quite a lot of configuration options on the way, but this is a basic outline to get a media browser like this:
(The search part can contain any/multiple exposed filter like a "normal" view) enter image description here

I recommend this tutorial for additional information
https://www.electriccitizen.com/blog/media-libraries-drupal-8
(but I personally would not use Inline entity forms for media, better stick with Entity browser for selection and DropZoneJS for in-place uploading)

  • I get pretty far and then I have a browser that won't show any content. So, I'm trying to walk through this step by step to find where I'm making an error. Above you mention "Create a view of type Entity Browser...." I don't have that option under Add View, View Settings, "Show." Do you mean choose "Media" or "Files" for "Show:" and then add an Entity Browser on the next screen after hitting Save and Exit? I would then have "Master" and "Entity Browser" as my two displays. – blue928 Jan 22 at 17:26
  • I guess you are on this page: /admin/structure/views/add- create a view showing "Media". This is just the base entity type for the view items, but not the view (display) type. The view (display) type can be selected on the next screen and must be "Entity browser" – Hudri Jan 22 at 17:47
  • Updated the 2nd paragraph of my answer. Mind the mandatory Entity browser bulk select form field! – Hudri Jan 22 at 18:12

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.