I think it expects a non-string object, but is passed a string when an atom is dropped from the library onto a CKeditor window. Please can you confirm if this is a bug, or if I'm misunderstanding how it should work.

Drupal.theme.prototype.scaldEmbed ends with this code, suggesting that "options" is a non-String object that needs to be stringified:

  // If there are options, update the SAS representation.
  if (options) {
    output = output.replace(/<!-- scald=\d+(.+?) -->/, '<!-- scald=' + atom.sid + ':' + context + ' ' + JSON.stringify(options) + ' -->');
  }

But when an atom is dropped from the library onto a CKeditor window, the value that will be passed as "options" is built using sas2array, which just extracts the options substring from a SAS string.

So if the SAS for the atom is
[scald=105:sdl_editor_representation {"link":"http:/atom/33"}]

sas2array sets options to be
{"link":"http:/atom/33"}

after it runs through scaldEmbed it is output as
<div class="dnd-drop-wrapper"><!-- scald=105:sdl_editor_representation " {\"link\":\"http:/atom/33\"}" -->

This isn't the proper format. If I then try to right-click and edit the atom properties, the Link field in the pop-up window shows:
function link() { [native code] }

I'm trying to get this to work to implement setting a default value for a dropped atom (see issue https://drupal.org/node/2169385).

Comments

jcisio’s picture

Category: Support request » Bug report

The "options" can be either a string (for historical reason) or arbitrary data in "JSON-compatible" string.

The described behavior is indeed a bug. Drupal.theme.prototype.scaldEmbed should not JSONify the variable if it is already a string.

scotwith1t’s picture

This simple patch checks if the options variable is a string before JSON.stringify'ing it.

scotwith1t’s picture

Status: Active » Needs review
scotwith1t’s picture

StatusFileSize
new750 bytes

Oops. Wrong file.

nagy.balint’s picture

Title: What does Drupal.theme.prototype.scaldEmbed expect the "options" parameter to be? » [legacy plugin] options parameter should not be stringified if its already a string
nagy.balint’s picture

Title: [legacy plugin] options parameter should not be stringified if its already a string » [legacy ckeditor plugin] options parameter should not be stringified if its already a string
nagy.balint’s picture

Seems we could use a trim there, as the function expects options to not have any whitespace before or after, and when it gets a string from sas2array then it will have a whitespace already before.

  • nagy.balint committed 622256a on 7.x-1.x authored by scotself
    Issue #2227137 by scotself, nagy.balint: [legacy ckeditor plugin]...
nagy.balint’s picture

Status: Needs review » Fixed

Thanks, Committed.

Status: Fixed » Closed (fixed)

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