When wyswig is used for fields in file entity in combination with media_edit_all module the format from last entity is used.
The problem in function getFieldInfo, it uses wrong field info by dropping "--" from field id, even if this field is exist.

CommentFileSizeAuthor
#4 wysiwyg-baseField_check-2668848-0.patch782 bytesvzblk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vzblk created an issue. See original summary.

TwoD’s picture

Could you link to that module? I can not find it.

vzblk’s picture

It is a part of media module.
Sorry, wrong name
media\modules\media_bulk_upload
I already found a solution:
Just add a check if the field is exist.
var baseFieldId = ((fieldId.indexOf('--') === -1 || $('#' + fieldId).length)? fieldId : fieldId.substr(0, fieldId.indexOf('--')));
In getFieldInfo function in wysiwyg.js file.

vzblk’s picture

Patch provided

TwoD’s picture

Could you list the exact steps needed to reproduce the problem?
I tried bulk-uploading several image fields with the image file entity having a WYSIWYG-enabled field on them. No form with and editor was shown even when I made a field required.

vzblk’s picture

  1. Create content type with filefiled with the unlimited cardinality
  2. Add a node and upload multiple files
  3. Press Edit All button. You will see a list of forms for each file
  4. Change the formats for some text fields with wysywigs (for each file)
  5. Save changes
  6. Press Edit All again. You will see the same activated wysywyg for the same field for all files. (note: you can see that actual format in select list selected correctly). E.g. format will be CKEditor but actual active wysiwyg will be the format from field from last file, e.g. plain text.
TwoD’s picture

Thanks, will see if I can take a closer look later today. I couldn't find a file field widget which gives me the "Edit All" button. All I get are individual Edit/Remove buttons with the "Media browser" widget. Does it change with the number of files uploaded or are you using some other widget?
The ones I have are the "File" widget (just gives me a Remove button), and the aforementioned "Media browser" widget.

I think this problem will come down to the multiple forms actually being the same form rendered multiple times, so Drupal needs to append the '--' suffix to avoid id collisions. That's a bit problematic since we need to the logic in getFieldInfo to look up the correct field instance information every time a field instance is added using "Add another item" buttons. Each time a multi-value field gets a new item/instance Drupal will send down all the field instances again and re-render them all.
The client sends along a list of all element ids currently in use on the page with each AJAX request, and the server appends/increments the '--' suffix if the element it's about to render would collide with one of those ids, in case the client does not remove the old field instances once it gets the response.
Wysiwyg strips this suffix to be able to keep track of and restore the editor state (enabled/disabled, etc) after each AJAX operation.
I think with the patch in #4 you'll find that the editor state wasn't restored correctly if you disable some of the editors in a field instance and then click 'Add another item'. This is because a field instance with the passed in '--' suffix will always exist (the server just created it) and Wysiwyg will then try to look up state information based on that id. Since that information does not exist, the editor will be disabled and/or you'll get a crash.

I'm guessing Multiple forms is used to merge the forms. Maybe it should be using its own suffix (or prefix) and not rely on Core's id de-duplication.

vzblk’s picture

We use this module, you can install it to easy reproduce the problem.
https://github.com/ericduran/drupal-media-edit-all
You right, it uses multiple form module to create one big form.
I believe that the easiest way to fix it is just to add additional logic to getFieldInfo function, I'll try to find better solution based on your suggestion.

steinmb’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
Status: Needs work » Needs review
TwoD’s picture

Status: Needs review » Postponed (maintainer needs more info)

Which module versions are you using? (Media, Media Bulk Upload, Plupload, File Entity, etc.)
I've been testing with Media 2 and the latest version of the others.

I can not get the media_edit_all module linked above to do anything at all.
It's looking for element ids starting with field-media-items-add-more-wrapper but can't find any.
Even if I specifically add an unlimited field of type "File" and name it 'media' it would still never match anything because there's no element created with an id suffixed add-more-wrapper like for other fields.

The plain "File" widget uses an upload form instead of an "Add more" button. This one has no Edit buttons.
The "Media browser" widget only has an "Attach media" label and a "Browse" button.

I can see what the media_edit_all module is trying to do, but can't see how it could possibly work without a field named exactly "media" and perhaps some unknown version of Media module. I didn't bother testing the Media 7.x-1.x versions as it's simply been way too broken for me in the past with the Wysiwyg integration. I did try to scan through its code in search for what could create elements with ids like mentioned above, but found nothing.