$class = isset($items[0]['override']['class']) ? $items[0]['override']['class'] : NULL;
    $style = isset($items[0]['override']['style']) ? $items[0]['override']['style'] : NULL;

should be

$class = isset($items[0]['override']['attributes']['class']) ? $items[0]['override']['attributes']['class'] : NULL;
$style = isset($items[0]['override']['attributes']['style']) ? $items[0]['override']['attributes']['style'] : NULL;

I found that while trying to figure out while the alignment and styles were not being saved when adding a media colorbox formatted image through the Wysiwyg.

That was part of the problem not all of it. After fixing that, the style gets saved, but you lose it again on re-edit. The alignment value never gets saved at all. I wound up doing this:

    $class = isset($items[0]['override']['attributes']['class']) ? $items[0]['override']['attributes']['class'] : NULL;
    $style = isset($items[0]['override']['attributes']['style']) ? $items[0]['override']['attributes']['style'] : NULL;
    $align = isset($items[0]['override']['attributes']['align']) ? $items[0]['override']['attributes']['align'] : NULL;
    if($align) {
      $style = isset($style) ? $style . 'float:' . $align : 'float:' . $align;
    }

Bit that was only a quick fix. All these values get lost again on re-editing the node. If you make function media_colorbox_field_formatter_view return nothing at all while on an edit page, then you get a placeholder image, but the styles and alignment are correct.

Using Media 7.x-2.x-dev.

Comments

kjl’s picture

Title: Missing elements in formatter view, plus alignment in Wysiwyg is not saved. » Missing properties in formatter view, plus alignment in Wysiwyg is not saved.
leanne9’s picture

I am sorry I am no help... but maybe you can help me-- how are you getting Media Colorbox to work in a WYSIWYG at all? With the "add media" button I can insert an image if I select "Current format is: Large" which goes in as

[[{"type":"media","view_mode":"media_large","fid":"875","attributes":{"alt":"","class":"media-image","height":"140","typeof":"foaf:Image","width":"480"}}]]

and it renders the photo correctly ... But if I select the "Colorbox" format it gives
[[{"type":"media","view_mode":"colorbox","fid":"875","attributes":{"alt":"","class":"media-image","typeof":"foaf:Image"}}]]
which renders as "image-x-generic.png" (grey icon image).

I am using the TinyMCE editor.

makli’s picture

I've the same problem as kjl. If re-editing the node in the wysiwyg-editor the previously adjusted float-settings get lost.

jurgenhaas’s picture

Same problem here. Also, $class and $style will be arrays and should be imploded before used as #item_class and #item_style in the themeing variable array.

David_Rothstein’s picture