Wouldn't it be nice if site builders could configure how all of their Media should be displayed in different contexts using an understandable, intuitive UI? This has been a challenge since the beginning of the Media project. Prior to 1.0-beta5, this challenge was punted off to the Styles UI module within the Styles project, which has not yet become mature. With 1.0-beta5 and 2.x, we've dropped the Styles module dependency, and are instead punting this off to the File Entity module. Here's what that UI currently looks like for configuring how to display Video as "Large":

manage-file-display.jpg

This is the same interaction pattern as configuring input filters for a text format, because the underlying data model is the same: you need to select multiple things to enable from a code-determined set of options, you then need to configure order, and for some of the enabled items, there might be settings. However, while this maps to the data model used by the code, I don't think it really makes much sense to site administrators.

Ok, so what's the disconnect? I think it's that administrators are more likely to think: "I want to configure my local QuickTime video display. Now I want to configure my local Flash video display. Now I want to configure my YouTube video display. Now I want to configure my Brightcove video display. And so on." rather than: "I want to configure my Video display. Ok, since a particular video asset can be any of these kinds, I need to enable all of their formatters, and then prioritize them." The Styles module is a little closer to this pattern, where modules can define "containers" (e.g., YouTube video) that are distinct from "type" (e.g., Video), but that module has not yet successfully mapped that pattern to a solid UI. Also, the Styles module API for managing containers is a bit too rigid to cover some of the interesting use-cases (like display a YouTube preview image when inside a WYSIWYG editor vs. the video itself when viewing the node) without baking that "business logic" directly into the rendering functions.

I think before going too far down the road of solving this specific UX issue, it's worth stepping back and revisiting our assumptions about what a media "type" is anyway. By default, the Media module defines the types as: Image, Audio, Video, and Other. This type then becomes the basis for the field bundles, meaning you can configure different fields for each of these types. So, for example, the Audio type can be given a "Lyrics" field, which wouldn't really make sense for the other types. Also, different bundles allows for different settings on the "Manage Display" page of the Field UI. So, for example, you might want to configure a "Description" field to display differently for images vs. audio. However, for a given type, the fields and their display settings are the same, so if you add a "License" field for Video, it operates the same regardless of whether you have a local video or a YouTube video, even though it might not make any sense for the latter case.

Meanwhile, how much should we support configurability of type definitions? In #1227084: Provide built-in support for pre-defined file types, we pushed the standardization of "audio", "video", "image", and some others, from the Media module, upstream to the File Entity module, with some good justification for doing so coming from a MIME standard. Additionally, HTML 5 includes <audio> and <video> tags to complement the <img> tag, providing yet more justification for treating "image", "audio", and "video" as a useful, standardized axis on which to distinguish media assets. However, what about "album" or "playlist"? Should those be media types? What about "photo", "illustration", and "screenshot"? What about "local video" and "remote video"? Do we lump all of this into media "types", or reserve "type" for something we can standardize on, and provide some other concept to capture site-specific business logic? And if we provide some new concept, do we actually need two: one for use in configuring fields, and a different one for configuring "manage file display", bringing us back to the original UX question.

Anyway, lots of questions. No answers from me at this time. What are your thoughts?

Comments

dave reid’s picture

Title: Revisit our assumptions about file/media types » Revisit or reconcile our assumptions about file types vs media types
Issue tags: +Media Sprint 2011
arthurf’s picture

effulgentsia’s picture

We discussed this extensively so far at the sprint. What we came up with is that the type bundles should be administrator configurable. Just like there's a UI for adding/removing content types (e.g., Article, Basic Page, etc.), there should be a UI for adding/removing file types (e.g., Photo, Animation, etc.). The UI should allow for configuring which mime types are allowed for each type. For example, Animation might be set to allow application/x-shockwave-flash and image/gif, Image might be set to allow image/gif, image/jpeg, and image/png, and Document might be set to allow application/msword, application/pdf, text/csv, and a bunch of others. As can be seen from the above examples, it should be possible for:

  • multiple bundles to allow some of the same mime types (e.g., Animation and Image might both allow image/gif), and for
  • a type to include mime types from different mime type directories (e.g., Document might allow some text/* mime types and some application/* mime types).

The above will let us remove things in the current UI that are file extension based, and abstract to file type. For example, when configuring file fields, we can replace the "Allowed file extensions" and "Allowed remote media types" settings with a single "Allowed types" setting, as shown here:

Only local images are allowed.

We'll need to figure out a good UI for allowing the administrator to specify the allowed mime types for a file type. We can leverage the fact that there's a known maximum set provided by file_default_mimetype_mapping() (of course, extendable) to create a page with lots of checkboxes instead of requiring the administrator to type mime types into a textfield.

We'll also need to provide a default set of types, at least including Image, Audio, and Video, as we currently do, and some decisions still need to be made with respect to Document and/or Other. We'll also need to decide which mime types to allow by default for each of these default types (e.g., should image/tiff and other non-web-renderable images be allowed by default for the Image type?).

We'll also need to decide what file type to assign to an uploaded file if its mime type is allowed by multiple file types. Our default file types won't have such intersections, but for example, if the administrator does create a Animation file type that allows image/gif, and a file field is configured to allow either Image or Animation, and a gif file is uploaded, the system will need to decide whether to assign this file the Image or the Animation type. Possibly, we can just pick one, and allow modules to alter the decision, or else we can provide a confirmation form to let the user performing the upload decide. Since our default file types won't be configured in this way, we can defer the optimization of this user experience to future issues.

This will also allow us to simplify the "Manage file display" page (see screenshot in the issue description), if we allow hook_file_formatter_info() to specify which mime types the formatter can act on. That way, for a particular file type, we can limit the list of formatter checkboxes to only those that make sense for that file type.

Much of this can and should be implemented in the File Entity module. We might move this issue to that project soon, but leaving it in Media for now, because some of the code affected is the Media Browser widget which will remain in the Media project.

Anyway, this is our roadmap for now. Please provide feedback if you have any. To accomplish the implementation of it, we'll break it up into several issues.

effulgentsia’s picture

Title: Revisit or reconcile our assumptions about file types vs media types » Provide administrative UI for adding/removing file types, and customizing the mime types allowed for each file type
Project: D7 Media » File Entity (fieldable files)
Version: 7.x-2.x-dev » 7.x-1.x-dev
Category: task » feature
Priority: Normal » Critical

Moving to File Entity project. This is a required feature for it.

aaron’s picture

davereid suggested an autocomplete which might work in place of the 300+ checkboxes. the autocomplete could be formed as 'Mimetype (ext)' to make it easier.

aaron’s picture

Assigned: Unassigned » aaron
aaron’s picture

bryancasler’s picture

subscribe

effulgentsia’s picture

Assigned: aaron » Unassigned

As an update here, there's now a working patch in #1292382-24: Make it possible to create any number of custom File Types that gets us a good part of the way towards #3. Once that's committed, work on the follow-ups will be able to proceed.

dave reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

File entity has switched to a 7.x-2.x branch and the 7.x-1.x branch is no longer used. Please make sure to update your Git clones.

shenzhuxi’s picture

I'm the author of apachesolr_media and file viewer.
The file_entity and media issues make developers confused now.
For my module I need setting per mime type. I think file_entity should provide settings for each mime type.
For display different files, per mime type settings are also necessary.

Maybe the bundles are the only thing to leave to media module now.

effulgentsia’s picture

@shenzhuxi: can you describe which settings you've found to be needed per mime type? thanks.

shenzhuxi’s picture

For example, a parser for each mime type to extract the text to make index.
catdoc for .doc file, xls2csv for .xls file, catppt for ppt file.
docx, pptx, xlsx, epub files are all zip files, but need separated settings to get the content.
I think for video or audio bundle, you can't really use one lib to get all the meta data out either.

shenzhuxi’s picture

Will settings for each type be storaged in file entity way or in media way (save in a table) in the future?

I'm working on OG based group file management. I realised that BUNDLEs should be configurable and shouldn't be linked to MIME system.

dave reid’s picture

Priority: Critical » Major
Issue tags: -Media Sprint 2011

Downgrading this to major for now.

shenzhuxi’s picture

/**
* Determines the file type of a passed in file object.
*
* The file type is determined by extracting the 'first' part of the file's
* MIME type. For example, a PNG image with a MIME type of 'image/png' will
* have a file type of 'image'.
*
* @link http://www.iana.org/assignments/media-types/index.html IANA list of official MIME media types @endlink
*/
function file_get_type($file)

I think this way is not a good idea for bundles. It's better to allow user define bundles like node.

tsvenson’s picture

Status: Active » Postponed

I'm setting this to postponed for now since the patch in #1292382: Make it possible to create any number of custom File Types will completely change the way file types works.

ParisLiakos’s picture

Status: Postponed » Active

Its in:)

tsvenson’s picture

Yes please, now when #1292382: Make it possible to create any number of custom File Types is in, its time to get back to this so we can create new file types too. Currently its only possible to edit the default ones and that kinda limits the usefulness of that patch.

ParisLiakos’s picture

Title: Provide administrative UI for adding/removing file types, and customizing the mime types allowed for each file type » Provide administrative UI for adding/removing file types
Status: Active » Needs review
StatusFileSize
new2.88 KB

Simple patch, provides a way to add file types:)

ParisLiakos’s picture

StatusFileSize
new2.89 KB

This gets rid of a fatal error when editing a file type, pointed by Rob_C on IRC:)

Rob C’s picture

Applies clean.

Status message
The file type robstest has been updated.

Nice! (Save on edit now also works indeed.)

Tested mime types, validation seems to work.

1 thing i can't seem to find, a delete button. Arg how can i get rid of this thing now! :)

ParisLiakos’s picture

Status: Needs review » Needs work

Do we need to lock default file types?
Thats why i did not start adding a delete button..I think we should allow deletion of default types..
Putting to needs work for deletion

rooby’s picture

You can delete default content types & menus etc. so I don't see why not.

Jackinloadup’s picture

I think there should be a way to lock Media types, but only ones explicitly created by other modules or exported into code with something like features or similar. I agree that "default" types should be removable.

Though I think that functionality could be handled in a separate issue so it doesn't prevent this one from moving forward.

Thoughts?

RobW’s picture

#26: There was a similar discussion in #1043198: Convert view modes to ConfigEntity for view modes in D8 core. Probably worth a look.

slashrsm’s picture

Tested #22. Works great.

I agree that we need to allow delete operation. I also agree that we need to allow modules to create file types that are undeletable or somehow uneditable. We could take inspiration from node.module about this. Every node type has several arguments in node_type db:
- custom: indicated whether type was introduced by a module or created via UI. Types that are introduced by a module are not deletable.
- locked: indicates whether machine name changes are allowed via UI or not.
- disabled: indicated whether type is disabled or not (disabled types stay in DB, but are not displayed in UI).

Could we implement some of this features for file types also? It would definitely solve our problem of (dis)allowing delete operation.

ParisLiakos’s picture

Status: Needs work » Needs review
StatusFileSize
new5.71 KB

stole some code from node content types deletion and voila:P
we might need a custom flag, so deletion can be prevented if provided by a module, but aye this should be another issue

ParisLiakos’s picture

Issue tags: +Needs tests

Ah, just saw #28..yes we should provide this functionality..but also agree with #26..lets leave this for other issue, since this functionality is more urgent need i think.btw we need tests here

slashrsm’s picture

Status: Needs review » Needs work
+++ b/file_entity.admin.incundefined
@@ -481,3 +521,37 @@ function file_entity_file_type_form_submit($form, &$form_state) {
+  $t_args = array('%name' => $form_state['values']['name']);

I get a Notice: Undefined index: name here.

There are no "delete" links on admin/structure/file-types. I think we should add them to achieve standard experience.

ParisLiakos’s picture

Status: Needs work » Needs review
StatusFileSize
new6.49 KB

good catch! fixed PHP notice and added delete link in file-types overview admin page

slashrsm’s picture

Status: Needs review » Needs work
+++ b/file_entity.admin.incundefined
@@ -385,6 +396,18 @@ function file_entity_file_type_form($form, &$form_state, $type) {
+  $form['type'] = array(
+    '#type' => 'machine_name',
+    '#default_value' => $type->type,
+    '#maxlength' => 255,
+    '#disabled' => (bool) $type->type,
+    '#machine_name' => array(
+      'exists' => 'file_type_load',
+    ),
+    '#description' => t('A unique machine-readable name for this file type. It must only contain lowercase letters, numbers, and underscores.'),
+  );

'#type' => 'machine_name' would be much sexier here :)

http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc...

I noticed another thing. Default types are exported to code. When you delete them they stay there (they are only reverted to state reflected in code). I propose that we:
- Remove "Delete" button if we have unmodified type defined in code
- Change "Delete" button with "Revert" if we have type, that was exported, but later modified and saved to DB

I know that we planned to divide this in two issues, but now when I understand that we actually have types that are 100% saved in code, I do not see this feature without proper handling of those.

ParisLiakos’s picture

'#type' => 'machine_name' would be much sexier here :)

its already machine_name, although i have no clue, why js wont work

I noticed another thing. Default types are exported to code. When you delete them they stay there (they are only reverted to state reflected in code). I propose that we:
- Remove "Delete" button if we have unmodified type defined in code
- Change "Delete" button with "Revert" if we have type, that was exported, but later modified and saved to DB

Like image styles UI does...Well tbh, i would prefer removing file_entity's hook_file_default_types implementation and moving creation in the install hook..
That would allow two things:

- Make default types exportable through features
- No need implementing all this complex code:)

slashrsm’s picture

its already machine_name, although i have no clue, why js wont work

You most likely need to implement "#machine_name => source".

- Make default types exportable through features
- No need implementing all this complex code:)

I can agree with the first line, but this does not prevent us from implementing support for this. We still need to support hook_file_default_types() for other modules/features, which means that we need to implement that complex code.... :)

ParisLiakos’s picture

StatusFileSize
new6.52 KB

ha, yes source parameter defaults to name, while we have label:/ fixed that..
and, second point, yeap seems you are right..i will steal some code from image styles now:)

cosmicdreams’s picture

Status: Needs work » Needs review
slashrsm’s picture

Status: Needs review » Needs work

"Revert" functionality needs to be added.

rooby’s picture

slashrsm’s picture

Status: Needs work » Reviewed & tested by the community

At today's meeting we agreed that we can commit this for alpha1 and add revert functionality in alpha2.

slashrsm’s picture

slashrsm’s picture

rooby’s picture

Yay. I have been using this for a little while with no issues.

ParisLiakos’s picture

Status: Reviewed & tested by the community » Needs work

still needs tests

arthurf’s picture

In order to delete/disable file types defined in code I think we have to add a disabled status- this suggests that we tackle the revert issue along side of this.

arthurf’s picture

StatusFileSize
new13.04 KB

This is a rough patch which includes disable/enable/revert/delete functionality. As usual I'm not sure if this is the best approach but I think it gets us further along.

arthurf’s picture

Status: Needs work » Needs review
aaron’s picture

Status: Needs review » Needs work

This looks great, however when I add a new file type and disable it, I do not get a link to enable it again, even though the status reads "disabled". Additionally, for UI, I think that we should push any disabled types below the enabled types, and grey them out.

arthurf’s picture

Status: Needs work » Needs review
StatusFileSize
new13.04 KB

This is a reroll with a fix for the enable link. I don't see an obvious css class for displaying a row as disabled- any suggestions?

arthurf’s picture

StatusFileSize
new13.6 KB

Another reroll with the class that Aaron suggested in IRC

Status: Needs review » Needs work
Issue tags: -Needs tests

The last submitted patch, 1260050.50.diff, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

#50: 1260050.50.diff queued for re-testing.

slashrsm’s picture

StatusFileSize
new681 bytes
new13.91 KB

Added code that moves disabled types to the bottom of the list.

aaron’s picture

Status: Needs review » Needs work

This looks much better. However, when you add a new type, and then disable it, delete it, and recreate it, it will reappear disabled.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new14.31 KB
new1.07 KB

CToolS store disabled/enabled info in a variable, which is not updated on delete. This patch fixes it. I am not sure if there is any better way to do this via ctools_export API.

I also changed 'revert' link to 'delete' when file type does not have version in code. It seems much more understandable what link actually does.

bneil’s picture

Status: Needs review » Needs work

I tested out the patch in #55.

I was able to successfully create a new file type via the UI and use it via a file field and everything worked as expected. I also allowed this file type to be added via the WYSIWYG and was able to add one there as well.

I then disabled the file type.

I also changed 'revert' link to 'delete' when file type does not have version in code. It seems much more understandable what link actually does.

When I tried to delete the file type, the delete link went to admin/structure/file-types/manage/X/revert which was confusing since I thought I was deleting. Also, on this confirmation form the title is "Are you sure you want to revert the file type X?" and the button is "Revert", not Delete. I clicked Revert anyways and was directed back to the file types list and my custom file type was deleted, but the status message is "The file type X has been reverted."

Could we have the delete link go to a delete confirmation instead of the revert? I anticipate how it currently works may still be confusing for site builders.

This is going to be a great addition once it's committed.

aaron’s picture

Status: Needs work » Needs review
StatusFileSize
new14.31 KB

This fixes that issue. It should be good to go now.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

ParisLiakos’s picture

Status: Reviewed & tested by the community » Needs work

thanks for the effort all, but i dont see any tests yet

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new7.05 KB
new21.36 KB

Here we go. Let's see what test bot has to say about that... :)

ParisLiakos’s picture

Assigned: Unassigned » ParisLiakos
Status: Needs review » Reviewed & tested by the community

Awesomeness!! thanks a lot for writing tests slashrsm:) i am gonna check and commit this when i find some time:)
thanks all!!

aaron’s picture

Status: Reviewed & tested by the community » Fixed

I got it first. Thanks so much for your hard work, everyone!

http://drupalcode.org/project/file_entity.git/commit/70081d0

ParisLiakos’s picture

Yay!

slashrsm’s picture

Yay! One step closer to alpha. Thank you all!

tsvenson’s picture

Awesome. Bucketload of karmapoints to everyone involved!

ParisLiakos’s picture

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

Anonymous’s picture

Issue summary: View changes

Slightly reworded 2nd to last paragraph to account for #1227084 having landed.