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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaare created an issue. See original summary.

kaare’s picture

Issue summary: View changes
kaare’s picture

Assigned: Unassigned » kaare
Issue summary: View changes
Status: Active » Needs review
FileSize
43.52 KB
3.75 KB

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

kaare’s picture

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

[[{"type":"media","fid":"4","view_mode":"full","attributes":{"height":482,"width":354},"values":"global","alignment":"center"}]]
kaare’s picture

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

kaare’s picture

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

kaare’s picture

Rebase. Chasing latest commit in #2945188: Clean up media tokens

kaare’s picture

Some more discussion/argumentation around the property values: (global|override) in the token schema:

  • Elaboration around #6: media_wysiwyg_format_form() is the main source for building media instance settings, and is done so client side using jQuery.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.
  • Using radios is more verbosive and future compatible in the sense that you tell where the field values comes from, instead of just saying "the fields are overridden."
  • To explicitly differ from the token 3.0 format we should avoid using fields as property, as this is already used there.
  • It could make sense to use the term 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.

kaare’s picture

  • Renamed schema property 'values' to 'instance_fields'
  • Added options to token schema and improved token validation. (Guilty of issue context leakage, I know).
kaare’s picture

kaare’s picture

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

joseph.olstad’s picture

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

kaare’s picture

Thx!

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.

joseph.olstad’s picture

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

kaare’s picture

Altered description of radio selector description.

kaare’s picture

Ignore previous patch. it's wrong. Fix coming up.

kaare’s picture

joseph.olstad’s picture

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

kaare’s picture

Patch didn't apply cleanly any more. Rebased.

kaare’s picture

  • kaare committed f911d69 on 7.x-4.x
    Issue #2945631 by kaare: Consider using an "opt in" for overriding file...
kaare’s picture

Status: Needs review » Fixed

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

Status: Fixed » Closed (fixed)

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