Hello,

It's straightforward enough to create a new file_entity bundle type, but how to make that bundle type an 'image' type, and furthermore how to create a new bundle instance of that type?

For example, I created an "Avatar" file_entity type. For mimetypes, I put 'image/*'. I created it, then went to that type's 'Manage File Display' tab and the only formatters available were purely generic. No image formatters.

I worked around this by implementing hook_file_formatter_info_alter() and adding my bundle type to the 'file types' key if it's in there for images:

/**
 * Implements hook_file_formatter_info_alter().
 */
function mymodule_file_formatter_info_alter(&$info) {
  foreach ($info as $key => $data) {
    if (isset($data['file types']) && in_array('image', $data['file types'])) {
      $info[$key]['file types'][] = 'avatar';
    }
  }
}

Okay, now I have image formatters in there, and I proceed to set all those.

Next, on to adding an "Avatar" image:

First I tried a straight file/add .. But nowhere am I asked "Image" or "Avatar", and after uploading the system assumes Image and no choice offered to change that afterwards, either.

Next, I tried creating on a node content type a File field with Media Selector as the widget. In the options, the only "Allowed remote media types" selected is Avatar. I then went into a node edit screen and attempted to upload an image. Again, the same thing, it assumes I mean Image and that's it.

I'm guessing this is a mimetype issue, but any file entity bundle type that contains 'images' is going to need to have to share the same mimetypes with other 'image' bundle types.

Thank you all

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

Title: How to create additional Image file type? » Decide if formatters restricted to specific file types should be available to custom file types
Category: support » task

Retitling to better explain the issue.

Marked #2087067: YouTube formatters should declare supported MIME types as a duplicate.

Dave Reid’s picture

This would indicate there is a bug in #2067939: Restrict certain file formatters (audio and video) to only file types that have mime types that match wildcards then? Because adding image/* to the file type mime type combined with the changes that file_entity_file_formatter_info_alter() makes, it should work automatically.

Dave Reid’s picture

Based on the fact that there are problems during upload I would think this is more of a file type problem, and not with the file formatters.

Dave Reid’s picture

Status: Active » Closed (cannot reproduce)

I cannot duplicate this. I see that when I created a new 'Avatar' file type with the mimetype 'image/*' I had the image formatters available under 'Manage File Display' and uploading a new file offered me the choice between the files.

Dave Reid’s picture

Status: Closed (cannot reproduce) » Needs review
FileSize
1.19 KB

Ok it looks like there is an actual bug when file_view_file() is used. We didn't update the following code to use the mimetype restriction.

Dave Reid’s picture

Status: Needs review » Fixed
das-peter’s picture

Status: Fixed » Needs review
FileSize
666 bytes

Re-opening because the committed patch had / has an error:

+++ b/file_entity.file_api.inc
@@ -238,11 +238,13 @@ function file_view_file($file, $displays = 'full', $langcode = NULL) {
+      if (isset($formatter_info['mime types'])) {
+        if (!file_entity_match_mimetypes($formatter['mime types'], $file->filemime)) {

We've $formatter_info but not $formatter.

das-peter’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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