Problem / Motivation
This is a part of a major overhaul of the media tag format: #2945188: Clean up media tokens.
Inserted files in text areas using media browser will always override the field values from the file entity it refers to. There is no way for editors to let the actual file be the principal of inserted media's field values. The inserted token will use the current values from the file entity as they are at the time of insertion, but they will always be overridden.
Propose resolution
Introduce a new option in media_wysiwyg_format_form()
that lets editors either use values directly from the mother file entity or use overridden values for this inserted token. Add an elaborate explanation/warning about what happens when using values from the file entity and values there are changed. This option should be stored in the root of the media token, and might be combined with the actual overridden fields, so $tag_info['overridden_fields'] == NULL
means "don't use overridden fields" and $tag_info['overridden_fields'] = array('field_file_image_alt_text[und][0][value]' => …)
means "use overridden fields and here are the values."
As for the UI, the option should toggle the visibility of overridden fields or a rendered version of the fields as present in the file entity. Either/or.
Comment | File | Size | Author |
---|---|---|---|
#20 | media-2945631-opt-in-override-fields-20.patch | 8.72 KB | kaare |
|
Comments
Comment #2
kaareComment #3
kaareThis work is based on #2945188: Clean up media tokens and should be applied after. Using media_dev this works as expected. Using 'global' settings renders files with values from the file entity directly, vs using 'override' uses the values from the token:
Comment #4
kaareIn the battle of stripping down unnecessary and duplicate values from media token, I'm happy to say that with this in place and selecting 'global' as field source I've managed to get the media token down to this:
Comment #5
kaareThe only reason the last version worked was because of the carefully selection of allowed properties in the token done in #2945188: Clean up media tokens. This version does the actual test whether or not to use overridden field values from token.
Comment #6
kaareAnd while I remember it. This option is implemented as radios because jQuery.serializeArray() didn't detect or add the value from a simple checkbox when the values from this form is parsed client side.
Comment #7
kaareRebase. Chasing latest commit in #2945188: Clean up media tokens
Comment #8
kaareSome more discussion/argumentation around the property
values: (global|override)
in the token schema:media_wysiwyg_format_form()
is the main source for building media instance settings, and is done so client side usingjQuery.serializeArray()
. For some reason this function doesn't seem to pick up input values from single checkboxes, at least not in jQuery 1.4 which ships with Drupal 7.fields
as property, as this is already used there.field_values
to say there the field values are selected from, but this might confuse both developers and misc code about this being an actual field. Remember, fields are now flattened alongside other options in the token.But I'm open to alternatives as I think
values
still doesn't say enough about what the property does. On the top of my head we could use:value_source
. Where should the field values come from.instance_fields
. You get to have 'fields' as part of the property, which better explains whats going on.instance_field_values
. This fully explains what the property does, but it is very long.As I wrote the above suggestions, I immediately fell for
instance_fields
, because in combination with the actual values(global|override)
it leaves little doubt about what it does. Not too long either.Comment #9
kaareComment #10
kaareRebased after patch in #2945633: Upgrade and bump version of stored media tokens to 4.0.
Comment #11
kaareAs this feature adds an additional property of the media token, it should be added soon-ish before too many runs the token 4.0 upgrade. It doen't really affect the upgrade, but it should be part of what we call 4.0 of media instance tokens.
A review or some feedback of sorts is most welcome. Otherwise I'll just commit this at the end of this week.
Comment #12
joseph.olstadHad a look at the patch, looks good.
As for jQuery 1.4, we could impose a hard requirement for jquery_update and a minimum jQuery version for media 4.x if needed.
The jquery_update module is quite flexible, allows for varying jQuery versions per theme or by whatever criteria you want to impose. We can also use it to check jQuery version and could put a drupal_message and or watchdog message warning of minimum jQuery version. Or we could simply specify a version for when media needs it. There are possibilities.
Otherwise maybe straight Javascript solution or maybe a library we might want to add for whatever job necessary
I haven't tested this patch yet but the code looks good! Seems to make sense. Judging by the other great work you're doing on 4.x I have high confidence.
Comment #13
kaareThx!
I omitted the entire checkbox/jquery problem (which I think is independent of jquery version) by using radios instead. And it made sense to do it this way anyway.
Comment #14
joseph.olstadOK yes even better than fiddling with jQuery versions, sounds great.
Win win. I will try out 4.x dev and this patch this weekend hopefully, curious now.
Comment #15
kaareAltered description of radio selector description.
Comment #16
kaareIgnore previous patch. it's wrong. Fix coming up.
Comment #17
kaareComment #18
joseph.olstadI am testing this using the latest media_dev 4.x dev
I updated the make files with your two latest patches on the latest 4.x commit of media.
going to install it and try.
Comment #19
kaarePatch didn't apply cleanly any more. Rebased.
Comment #20
kaareNow with an actual patch!
Comment #22
kaareThis probably needs a follow-up regarding the actual UI and UX. For now this patch solves the overall problem: Use fields from token or from file entity.