Steps to reproduce:

  1. Create node with WYSIWYG editor that media support and allows the "HTML source" button (in the WYSIWYG, not a seperate text format for HTML content)
  2. Click the "HTML source" button and copy-paste this media token:
    <p>[[{"fid":"3","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":""},"type":"media","link_text":null,"attributes":{"class":"media-element file-width-200"}}]]</p>
    

    ... replacing the "fid" with a value that you know isn't present currently (probably none are available if this is a new node).

  3. When submit the dialog or switch back to normal mode, you'll get this Javascript error:
    Uncaught TypeError: Cannot read property 'tagName' of undefined
    

    ... originating from Drupal.media.filter.replaceTokenWithPlaceholder(), specifically line 47.

I think the solution is to not try and and process the token if the FID can't be found, and just leave the token text in.

I'll create a patch in a moment!

Comments

dsnopek’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB
new1.05 KB

Patch is attached!

(Note: I've also attached a 2nd patch that applies against the Media included in Panopoly which has a bunch of other patches. This is just for my personal convenience so I've marked it as hidden.)

dsnopek’s picture

Hrm! Interestingly, it looks like the Panopoly patch wasn't necessary and actually won't apply whereas the other one will.. :-) Sorry for the extra noise with the extra patch!

zerolab’s picture

Title: Inserting HTML with unknown token that has FID leads to fatal Javascript error » Inserting HTML with unknown token that has FID leads to fatal JavaScript error
Related issues: +#2317519: Blank WYSIWYG with existing multiple Media content

This is somewhat related to #2317519: Blank WYSIWYG with existing multiple Media content and the patch https://www.drupal.org/node/2317519#comment-9852867 from solves the error.

However, when you have multiple WYSIWYG inserted items (and multiple editors), some placeholders do not get rendered, but stay as media tokens.

Cheers,
Dan

dsnopek’s picture

I think staying Media tokens is fine. It's better than losing the data!

zerolab’s picture

I agree it is better than losing data.
#2317519-22: Blank WYSIWYG with existing multiple Media content has a patch that fixes both issues.

dsnopek’s picture

Title: Inserting HTML with unknown token that has FID leads to fatal JavaScript error » Inserting HTML with token that has unknown FID leads to fatal JavaScript error

Ah, #2317519-22: Blank WYSIWYG with existing multiple Media content definitely looks like it'd fix this issue too, but I can't vouch for the rest of the changes because I don't have steps to reproduce the other problems..

rooby’s picture

I have the same problem and it results in create_element gets called with no media and you get the following error on the first line in create_element():

Error: TypeError: html is undefined

My error is different because I'm using a slightly older version of media but it's the same root cause.

I'm not sure how viable it is to support copy and paste of media tokens however we need to at least make it so that it doesn't error out if source is empty. At a glance, the patch in the related issue #22 seems it would fix it.

It would possibly even be good to pop up a message to the user to let them know what's going on but maybe we can't be sure enough of the exact cause for that to be viable.

I agree that leaving the token if no matching media is found is preferable.

sambonner’s picture

I've applied the patch in #1 and while its a suboptimal situation to get into, this behaviour is much preferable to an execution error in the JS causing Ckeditor to die partway through initialisation.

rooby’s picture

@sambonner:

It looks like this issue will get closed in favour of the patch at #2317519-56: Blank WYSIWYG with existing multiple Media content.

Is there any chance you could see if that patch resolves your bug?

scuba_fly’s picture

I'm still having this issue with the latest dev which includes the #2317519-56 patch

joseph.olstad’s picture

Hi @scuba_fly , can you please test patch #1 in this issue, I just tried applying it and it still applies to the latest beta5 release or 2.x dev branch

Let us know if patch#1 addresses your issue.

  • joseph.olstad committed da1ccd9 on 7.x-2.x authored by dsnopek
    Issue #2491569 by dsnopek: Inserting HTML with token that has unknown...
joseph.olstad’s picture

Status: Needs review » Fixed

Thanks @dsnopek committed to dev branch 7.x-2.x

scuba_fly’s picture

A bit late, but confirming that the #1 patch at least lets you keep your data and can switch back to the editor mode.

Status: Fixed » Closed (fixed)

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