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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

samuel.mortenson’s picture

Is 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.

joachim’s picture

> 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:

  public function render(ResultRow $values) {
    /** @var \Drupal\file\Entity\File $file */
    $file = $values->_entity;

My guess is that $values->_entity is the base entity.

joachim’s picture

... 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.

samuel.mortenson’s picture

Status: Active » Needs review
FileSize
543 bytes

#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.

  • samuel.mortenson committed 0dae1bd on 8.x-1.x
    Issue #2807299 by samuel.mortenson: 'File Browser Preview' Views field...
samuel.mortenson’s picture

Status: Needs review » Fixed

I 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.