Automatic insertion in a available media field via the WYSIWYG media plugin.

You have a content type with a media field and a text field with WYSIWYG.

Use case to add a media in the WYSIWYG area
- in the WYSIWYG insert a media via the media browser.
- the media is automatically added in the available media field on node save or previously via ajax.

Use case to delete a media in the WYSIWYG area
- in the WYSIWYG delete a media.
- the media is automatically removed of the media field on node save or previously via ajax.

I guess this should be an option in the field settings "Add media uploaded from WYSIWYG".

Comments

renat’s picture

Subscribe

visuaLatte’s picture

I agree. This is a wonderful module and much better than the hodgepodge we worked with in D6, but the behavior I expected was that, once I added a field such as "caption" to a video or image, that this field would appear in the overlay along with the upload function (or, it would appear after an image was selected, kind of how FileField allows you do fill in Alt and Title fields after the upload is complete).

It's not such a big deal for me, but I expect that my clients won't find it intuitive to go to the Content >> Media tab and add captions there.

DamienMcKenna’s picture

Subscribe.

DamienMcKenna’s picture

Title:Fill in the media fields in WYSIWYG» Fill in the available fields when creating media

It should be possible to do via the normal overlay too.

mattcasey’s picture

+1000 nateeanes... thanks for the tip to look for the tab under Content, I spent forever trying to find the fields I added!

Docc’s picture

sub

DamienMcKenna’s picture

Priority:Normal» Major

So, how about adding support for fields but providing disclaimers that certain field types might not work well? Simple fields like text fields (caption/description), and maybe even references (user reference, term reference) should work ok, so in the interests of improving the UX (CX = Contributor Experience?) I think it'd be worth adding.

So, given that the media add form isn't a real entity edit page, what would be the approach to add the assigned fields? If someone could point me in a direction I'll start taking a look at it.

emackn’s picture

subscribe. I dont see how this was not part of basic functionality for the module. I just thought the module was broken when it didn't show attribute fields that were added to the asset type. Is there a technical limitation as to why it doesn't work this way?

rootwork’s picture

Subscribe

DanielF’s picture

I too would love to see this added. My clients can live the Content>Media tab, but this is the only thing now that's "bad" about the user interface for them. Bonus points if I can assign independent values for each use of some media, although I realize that's probably a ton more work.

rootwork’s picture

Are there any module maintainers who can give tips on how we can productively help with this process? If work has been started on this feature, we can test patches and whatnot, or if work hasn't been started we can focus on this feature specifically. I agree that this seems to be the one missing piece to what is otherwise a fantastic module!

JacobSingh’s picture

I guess we'd want to implement something similar to the formatting form that shwos after you pick something (but different...). One of the complications here is plupload which allows multiple files at a time... although that has a multi-edit screen, depending on how many files you upload it might get nasty.

James.elliot is working on a new browser not using an iframe, so whatever we build here would likely be dependent on that change.

carole’s picture

subscribe

Trunkhorn’s picture

sub

mightaswell’s picture

subscribe

sanderjp’s picture

I realy hope someone can make this happen anytime soon, because this is exactly what my client wants. To be able to add all information on one page, instead of adding say 20 images, then going to the media pages to add tags for each one seperately.
Maybe someone can provide tips for a temporary workaround?

mightaswell’s picture

I'd also like the user to be able to fill in extra fields/meta data about the "media" content at the time they are creating it but it doesnt look like that capability is coming as soon as I need it so..

I though I would create a new content type called 'document' that is used for things like pdfs, docs, spreadsheets, etc. basically "office" documents.. with fields like title, description, etc.

I'd then use the media module as a 'file field' for this type instead of adding fields directly to the media type.

This will allow my users to upload these types of files using the media widget and I still get the other fields I need. I figure I could also do the same thing with audio and video by creating video and audio content types.

Does this sound reasonable?

I'm pretty new to Drupal. Is this the wrong way to go about it?

renat’s picture

Mightaswell, hi!
Yes, this way is correct. The only problem is that we'll lost most of the advantages of Media module. For example, if you'll reuse your photo or video in another node, you'll have to insert meta data once again. In fact, it's pretty much like the way we used earlier, without Media.

sanderjp’s picture

Hey, there is already some code for this in media.module starting from line 1038 but it has the following comment:
"This section handles fields on media when media is added as a field. It is pretty unpolished, so hiding it for now."
I've just tested abit, but not very skilled in drupal programming yet, so maybe someone could have a quick look to see if that code is any good.
It does seem to work, except for the fact that it loads the media/%/edit page in an iframe and upon saving the site is loaded in the iframe, instead of closing it. Anyone an idea on how to fix that?

emackn’s picture

@renat, which branch/tag are you looking at? beta3?

renat’s picture

@emackn, no, it was dev version something like two month ago. But I don't think it matters in case we keep our data in node fields, not in Media entity fields.

emackn’s picture

just saying cause that code you were referring to doesn't seem to work any longer. There is a $file variable that is used but never set to a value.

danbohea’s picture

I'd really like to see this functionality too (I also thought it would already be in there).

jerdavis’s picture

Any progress on this? or on at least identifying all of the hurdles and possible solutions? This seems to be a critical expected feature.

One complication I remember being discussed at DrupalCon was the fact that we're detecting the media being submitted and assigning it to the right media type during file upload. We can't know if it's an image, video, audio, or other till the file upload has been completed, so we can't show the extra fields till that's complete.

If this is still a hurdle, why do we need to rely on file extension detection? When creating a media entity normally (IE: Not through plupload) can we not just have a user pick the media type they're adding and get all fields at once?

Perhaps this isn't a hurdle any more, if not it would be good to understand what the hurdles are and who is working on related code in which branches so that if anyone here does have the time and inclination to take this on we've got some ideas where to go.

sanderjp’s picture

Just to be clear (read #19), there is already some code to fill in the meta data when you upload a file at the add content pages.
The code however just loads the media/*number*/edit page in an iframe of that specific file, but its very basic and needs rethinking/recoding/extending. But it's a start, and so it is already possible.

In my opinion you either need a follow-up page after uploading the content in de media launcher window to fill in the extra fields, or the fields appear after you've uploaded/selected the file in the media launcher. It would be ideal to have the fields on the same page or in the same window, not opening a new window like the code does now.

PS i'm also missing the ability to add multiple files when adding content. I have a media file field which can add unlimited number of files, but when i select multiple files in the media library only the first one selected gets added.

rootwork’s picture

Version:7.x-1.0-beta3» 7.x-1.0-beta4

Updating this to the latest version, as this issue is still present.

@sanderjp You should file a separate issue feature request for your P.S.

aaron’s picture

we need to make sure this works when adding/editing media from a field as well as a wysiwyg.

rootwork’s picture

Absolutely!

kingjohnnet’s picture

subscribe

emackn’s picture

Do we need to rename this ticket to include wysiwyg in the title and create a new issue for added data via the node form?

bastnic’s picture

subscribe

aaron’s picture

bumping this up so i don't forget about it.

paranormals’s picture

Title:Fill in the available fields when creating media» Fill in the available fields when creating media in the WYSIWYG

Subscribing

victoriachan’s picture

subscribe

mansspams’s picture

subscribe

dellis’s picture

subscribe

doana’s picture

This would be a great feature and would really make media the solution for those of us who are upgrading from D6 with image assist.

zoon_unit’s picture

subscribe

aaron’s picture

Version:7.x-1.0-beta4» 7.x-2.x-dev

version change

camdarley’s picture

I subscribe too, but i think we have to think at plupload integration too (http://drupal.org/sandbox/pp/1244926).
What happen if we upload multiple files in an unlimited media field?
What about an "edit" link near of each media fields, with a colorbox or a collapsed form?

ZuluWarrior’s picture

Sub,

I'm surprised this piece of connective functionality has not progressed further!

I would say though that the best solution would be to fetch the media/NUMBER/edit fields via the forms API, and slap them in the row with the multimedia asset in it. This principle would work with multiple files of different types on the content type, as each file row would be embellished with its relevant form elements.

Hook the validation and submission of the form any your ready to go, no?

Anyway, just my initial thoughts on it before I have a look in media.module...

bforchhammer’s picture

Subscribing

rickvug’s picture

Subscribe.

One way to implement this would be on the insert screen where one selects the image size. Have a "render with fields" checkbox there that would reveal the fields to be edited before insert. The other use case would having an edit link along with each thumbnail within the media browser. That would concievably be handled by the view configured to the the media gallery as per #1139514: Overhaul the media browser code to not use an iframe, and be more understandable, maintainable, and extendable.

yareckon’s picture

sub

djanousek’s picture

subscribe

bmx269’s picture

Sub

effulgentsia’s picture

Status:Active» Closed (duplicate)

I think this is a duplicate of #1213252: Allow media file's fields to be edited in a modal or after upload in the media widget, but please re-open this issue if there's something being proposed here that's different than what's covered there. Thanks.

jlyon’s picture

sub

ZuluWarrior’s picture

Just fyi, regarding my plan in #41, I did a little proof of concept and was able to dump a form, called from the forms api into the 'Metadata' area that is rem-med out of the current build.

Unfortunately project time lines means I don't have time to pursue this just yet. Hopefully soon I will fond time to re-visit. And if I can finish it off i'll submit a patch for review, but thats a couple of weeks of at least.

heyyo’s picture

@camdarley Any update on your sandboz project ?
Since I'm using the last Media Browser Plus, the adding of multiple files to one field doesn't work anymore, no insertion is realized, even if we see it's doing something.

camdarley’s picture

@heyyo: I'm not a maintainer of this project, i just mentioned it because I'm using it on my sites. Note that I use Media Browser Plus too without any problem. You should add an issue about this. Unfortunately I'm not a good developer so I can't help you actually.
You probably should contact the main maintainer: pp from the project page.
Sorry for the misunderstanding.

gagarine’s picture

Status:Closed (duplicate)» Active

I don't think #1213252: Allow media file's fields to be edited in a modal or after upload in the media widget is covering the automatic insertion in a field via the WYSIWYG media plugin.

You have a content type with a media field and a text field with WYSIWYG.

The use case to add a media in the WYSIWYG area is
- in the WYSIWYG insert a media via the media browser.
- the media is automatically added in the available media field on node save or previously via ajax.

The use case to delete a media in the WYSIWYG area is
- in the WYSIWYG delete a media.
- the media is automatically removed of the media field on node save or previously via ajax.

I guess this should be an option in the field settings "Add media uploaded from WYSIWYG".

gagarine’s picture

Issue summary:View changes

Updated issue summary.

nikosnikos’s picture

This could be done with an automatic filling during presave of fields in hook_field_attach_presave :

<?php
// Auto filled field name. This field is filled with the medias included in entity body.
define('MEDIA_FILLED_FIELD', 'field_media_autofilled');

/**
 * Implements hook_field_attach_presave()
 * Add the medias inserted into long texts fields to the MEDIA_FILLED_FIELD
 */
function media_field_attach_presave($entity_type, $entity) {
  if ( isset(
$entity->{MEDIA_FILLED_FIELD}) && ($media_formats = _media_formats()) ) {
   
// File ids to be in the field
   
$fids = array();

   
// To get the bundle name for field_info_instances
   
$eids = entity_extract_ids($entity_type, $entity);

    foreach (
field_info_instances($entity_type, $eids[2]) as $field) {
      if (isset(
$field['settings']['text_processing']) && $field['settings']['text_processing']) {
        foreach (
$entity->$field['field_name'] as $lang => $texts) {
          if (! isset(
$fids[$lang])) {
           
$fids[$lang] = array();
          }

          if (
$texts && is_array($texts)) {
            foreach (
$texts as $text) {
              if (
in_array($text['format'], $media_formats)) {
               
$fids[$lang] += _media_fids_in_text($text['value']);
              }
            }
          }
        }
      }
    }

    foreach (
$fids as $lang => $lang_fids) {
     
$entity->{MEDIA_FILLED_FIELD}[$lang] = array();
      foreach (
$lang_fids as $fid) {
       
$entity->{MEDIA_FILLED_FIELD}[$lang][] = array('fid' => $fid, 'display' => 0);
      }
    }

    if (empty(
$fids)) {
      foreach (
$entity->{MEDIA_FILLED_FIELD} as $lang => $value) {
       
$entity->{MEDIA_FILLED_FIELD}[$lang] = array();
      }
    }
  }
}

/**
 * Get the text formats where media_filter is activated.
 */
function _media_formats() {

 
$cache_media_formats = cache_get('media_formats', 'cache_filter');

  if (empty(
$cache_media_formats)) {

   
$media_formats = array();

   
$formats = filter_formats();
    foreach (
$formats as $format) {
     
$filters = filter_list_format($format->format);
      if (isset(
$filters['media_filter'])) {
       
$media_formats[$format->format] = $format->format;
      }
    }

   
cache_set('media_formats', $media_formats, 'cache_filter');

    return
$media_formats;
  }

  return
$cache_media_formats->data;
}

/**
 * Generates an array of fid from inline tags.
 * @param
 * The String containing text and html markup of textarea
 * @return
 * An array of fids.
 *
 * @see _media_generate_tagMap()
 */
function _media_fids_in_text($text) {
 
$fids = array();

 
preg_match_all("/\[\[(.*?)]]/s", $text, $matches, PREG_SET_ORDER);
  foreach (
$matches as $match) {
   
$tag = $match[1];

    if (!
is_string($tag)) {
      return
FALSE;
    }

   
$tag_info = drupal_json_decode($tag);

    if (isset(
$tag_info['fid'])) {
     
$fid = $tag_info['fid'];
     
$fids[$fid] = $fid;
    }
  }

 
// @todo call hooks for custom modules
 
 
return $fids;
}

// @todo auto create the MEDIA_FILLED_FIELD field for entities selected in an admin page
// @todo build an admin page !
?>

This code can be added in media.module (to be tested) or this can be in a separate module (in this case replace media_ by mymodule_).

You'll have to clear the cache.

There's no admin page in this code so if you want to make this work you'll have to :
1- Add a field named field_media_autofilled to your entity (I only tested it on a node but it should work on any fieldable entity)
2- Enable media filter in a "Long text and summary" field on the same entity.

hesham883’s picture

@nikosnikos:
Thanks, I tried your code and it was great
I added the following hook to hide the field

function hook_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'article_node_form':
      $form['field_media_autofilled']['#access'] = FALSE;
      break;
  }
}

by this way I can use image from the field to display it in views ,rules....or any other module

thanks again

becw’s picture

This issue sounds really similar to #1664418: Replace custom WYSIWYG integration and support WYSIWYG Fields module instead, except that when you use WYSIWYG Fields, instead of using the "media" button in the WYSIWYG toolbar, you upload the media to a field, and then insert the field content into the WYSIWYG.

Would that workflow support this use case?

becw’s picture

Issue summary:View changes

Updated issue summary.