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
Comment | File | Size | Author |
---|---|---|---|
#7 | 2098921-file-view-file-formatter-mime-type-7.patch | 666 bytes | das-peter |
#5 | 2098921-file-view-file-formatter-mime-type.patch | 1.19 KB | Dave Reid |
Comments
Comment #1
Devin Carlson CreditAttribution: Devin Carlson commentedRetitling to better explain the issue.
Marked #2087067: YouTube formatters should declare supported MIME types as a duplicate.
Comment #2
Dave ReidThis 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.
Comment #3
Dave ReidBased 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.
Comment #4
Dave ReidI 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.
Comment #5
Dave ReidOk 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.
Comment #6
Dave ReidCommitted #5 to 7.x-2.x: http://drupalcode.org/project/file_entity.git/commit/7bb1498
Comment #7
das-peter CreditAttribution: das-peter commentedRe-opening because the committed patch had / has an error:
We've
$formatter_info
but not$formatter
.Comment #8
das-peter CreditAttribution: das-peter commentedDave was faster :)
http://drupalcode.org/project/file_entity.git/commit/5da1c0072893215a10a...