Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to create an entity browser for Media image entities.
I created a view for the browser, showing Media entities. I added the relationship to the file, and then the File: File Browser Preview field.
The view doesn't render at all.
Log shows this error:
> Error: Call to undefined method Drupal\media_entity\Entity\Media::getMimeType() in Drupal\file_browser\Plugin\views\field\FileBrowserPreview->render() (line 33 of modules/contrib/file_browser/src/Plugin/views/field/FileBrowserPreview.php)
Comment | File | Size | Author |
---|---|---|---|
#5 | file-browser-2807299-5.patch | 543 bytes | samuel.mortenson |
|
Comments
Comment #2
samuel.mortensonIs the File Browser field in your View set up to use the File relationship? Based on the error it looks like the Media Entity is being passed to the Views field plugin, which is unsupported.
Comment #3
joachim CreditAttribution: joachim as a volunteer commented> Is the File Browser field in your View set up to use the File relationship
Yes it is.
But I suspect the problem is that the field plugin is expecting to be on a File entity base. This looks like it might be the problem:
My guess is that $values->_entity is the base entity.
Comment #4
joachim CreditAttribution: joachim as a volunteer commented... though I'm not sure how necessary this is anyway.
I'm trying to build the same sort of browser that this module provides, but with Media entities, and coming rather a cropper: #2807311: provide Views plugins for masonry, rather than using custom text field & form alteration. I had assumed this particular field was a key component of this, but I'm not actually sure that it is now.
Comment #5
samuel.mortenson#3 reminded me of a fix I recently did for Lightning, which is a distribution that provides a feature-rich Media browser for Media Entities. You might want to check it out if you're building your own. I think there may be work on this going on at https://github.com/drupal-media/media as well.
Here's a patch which should fix your problem.
Comment #7
samuel.mortensonI haven't heard back in awhile, but this issue was blocking some other work I'm doing so I went ahead and committed the patch from #5. If you're still having issues, feel free to re-open.