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?

This question has an open bounty worth +100 reputation from blue928 ending in 4 days.

Looking for an answer drawing from credible and/or official sources.

  • 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
1

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.

Then create a view of type Entity browser. Configure a view based on media entities, with fields and filters of your 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)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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