This issue has been there before with other versions and other editors http://drupal.org/node/1835826#comment-6783518
I understand the CKeditor 4 integration is brandnew and so issues can arise.

If you insert an image via the Media Browser, it first inserts the image fine. But when you save or switch to source code, you just get a "false" instead of the media tag, which should be something like
[[{"fid":"3","view_mode":"default","type":"media","attributes":{"height":276,"width":300,"class":"media-element file-default"}}]]

Using CKeditor 3.6.x fixed the problem for me. So it must be the brandnew CKeditor 4 JS that is causing the issue. Maybe it does not like the formatting of Media tags.

Comments

eigentor’s picture

Title: CKeditor 4 converts Media tags to "false" » CKeditor 4 converts Media tags to string "false"
TwoD’s picture

This happens because the new content filter in CKEditor 4 removes Media's data-file_info attribute from its placeholders. That attribute holds the macro representation of the media file and failing to parse it results in false being returned instead.

This new filter has caused a lot of grief for users so far.

A workaround is to disable it completely by implementing hook_wysiwyg_editor_settings_alter() in a small module until we can find a more permanent solution:

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['allowedContent'] = TRUE;
  }
}
drupauler’s picture

> This new filter has caused a lot of grief for users so far.

Amen to that. Thanks for the workround.

sylus’s picture

Works great and solves http://drupal.org/node/1951964

sylus’s picture

I have found that the following works which is a bit less of a hammer approach:

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
      $settings['extraAllowedContent'] = array(
        'img[src,title,alt,style,width,height,class,hspace,vspace,view_mode,format,fid]',
      );
  }
}
Frank Pfabigan’s picture

this issue is linked to: http://drupal.org/node/1951964

solution is to write a custom module that fixes the issue. here is the code:

  1. create a folder "wysiwygpatch" in /sites/all/modules.
  2. inside: create a file "wysiwygpatch.info" with this content:
    name = Wysiwyg Patch
    description = Patch for WYSIWYG, http://drupal.org/node/1963270#comment-7267744
    package = User interface
    dependencies[] = wysiwyg
    core = 7.x
    files[] = wysiwygpatch.module
    
  3. create another file "wysiwygpatch.module" with this content:
    <?php
    /**
     * Implements hook_wysiwyg_editor_settings_alter().
     */
    function wysiwygpatch_wysiwyg_editor_settings_alter(&$settings, $context) {
      if ($context['profile']->editor == 'ckeditor') {
        $settings['allowedContent'] = TRUE;
      }
    }
    
  4. enable the module. media button should work now.
bsarchive’s picture

Hooray! Thanks Frank Pfabigan.

deggertsen’s picture

Thank you @Frank Pfabigan.

It would still be nice to have a permanent solution. I assume that there is something useful with CKeditors new filter? If not then maybe it should be disabled in this module by default. Thoughts?

dan_lennox’s picture

"$settings['allowedContent'] = True" was causing me issues after saving the node. But sylus's version in #5 worked for me.

Slight modification below to allow inserting links to generic files.

<?php
/**
* Implements hook_wysiwyg_editor_settings_alter().
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
      $settings['extraAllowedContent'] = array(
        'img[src,title,alt,style,width,height,class,hspace,vspace,view_mode,format,fid]',
        'a[type,length,href]',
      );
  }
}
?>
ThaJoa’s picture

Neither #6 or #9 is working for me.

I'm using the latest WYSIWYG & media dev versions with the latest full version of ckeditor.
Having the same issue with TinyMCE 3.8 (WYSIWYG).

TwoD’s picture

In #6; the line starting with "files" is not needed since the .module file will always be loaded.
Disabling ACF completely, which is what #6 does, should take care of the problem with Media's content being turned into "false" without issues. If something happens after a node is saved, something else is at work since Wysiwyg only runs PHP code when the form is being built and JS code before the form is submitted.

Once I or someone else gets around to working on #1956778: Ckeditor 4.1 ACF, we'll have a way to control ACF from the GUI and this should be significantly easier to deal with. I'm aiming to have that done before the next release, since CKEditor 4 support will be "officially" introduced then as well.

ThaJoa’s picture

You were right.

I was able to fix it by editing the text format's filter processing order.
I had to put ''Converts video tags to embedded code'' (from the video module) after the ''convert Media tags to markup'' option.

#6 now works for me.

Kristen Pol’s picture

I tried the more secure (?) version in #5 but it didn't work for me (I did clear the cache) so I went with the bulldozer approach in #6 and it did work ;) For the site in question, the bulldozer is fine... trusted users are using the wysiwyg.

spfaffly’s picture

Frank Pfabigan's solution #6 worked perfectly for me. Thanks!

galgeek’s picture

I am yet another relieved and satisfied user of Frank Pfabigan's #6

TwoD’s picture

Ok, I'm calling this a duplicate of #1956778: Ckeditor 4.1 ACF then, but I'll keep it open to be more visible in the queue for a little while.

TwoD’s picture

Status: Active » Closed (duplicate)
margaux’s picture

Thanks, @Frank Pfabigan! This was exactly what I needed, too.

tadesign’s picture

Thank you very much Frank Pfabigan for the module, that did the trick on a soon to be going live site and saved me hours of frustration!

Happy New Year all!

FiNeX’s picture

Issue summary: View changes

With the latest wysiwyg -dev release the module suggested on comment #9 is no more needed. I suggest to close this bug.

kenorb’s picture

PascalAnimateur’s picture

I figured out I should post here about how I got media 2.x video and audio to work with CKEditor ACF.
It's as simple as adding the following content rule :
video[controls];audio[controls];source[src,type]

bircher’s picture

To use the automatic ACF I added the following to the setting:

mediawrapper[!data];*[!data-file_info]
and the media elements didn't get turned to false any more.

PascalAnimateur’s picture

Strangely the latest -dev of file_entity / media don't seem to work with the previous two ACF rules. What I now have to use in order to have teaser break + all the media file types working:
img[title,alt,src,data-cke-saved-src](wysiwyg-break,drupal-content);video[width,height,controls,src](*);audio[controls,src](*);img[*](media-element,file-default)

dw72’s picture

I still have "false" with settings from #24. Can I insert it in 'Content rules' field in wysiwyg module settings or must use own module for this?

TwoD’s picture

This is the downside to having to manually specify the content rules. Modules can change how they do things (maybe just in some situations) behind your back...

I wrote a patch ago to allow modules to add rules on their own. I think I've uploaded it but I can't find it now. I'll create a new issue as a follow-up to this one if I can't find it.

alex.skrypnyk’s picture

Added <source> tag to rules above. Updated code below.

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function YOURMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['extraAllowedContent'] = array(
      'img[title,alt,src,data-cke-saved-src](wysiwyg-break,drupal-content);video[width,height,controls,src](*);source[src,type];audio[controls,src](*);img[*](media-element,file-default)',
      'a[type,length,href]',
    );
  }
}
Murz’s picture

This problem is sometimes happens on fresh Media and CKEditor module - not each time, but at random. Seems that provided solutions is for Wysiwyg module, did you have solution for CKEditor module?

Murz’s picture

lsbbs’s picture

I added to pictures with entity view modes and file entity an additional field to the image to display a caption text.
After applying the patch mentioned here in #6 this was working fine with ckeditor 4.3.0.1e748a6.
Now I added a second field for photographers credits which should be a link.
In the editor it looks then like this:

[[{"fid":"19","view_mode":"story_image_left","fields":{"format":"story_image_left","field_file_image_alt_text[und][0][value]":"Hazabe","field_file_image_title_text[und][0][value]":"Hazabe","field_caption[und][0][value]":"Hazabe after hunting","field_photo[und][0][title]":"Gideon Shea","field_photo[und][0][url]":""},"type":"media","attributes":{"alt":"Hazabe","title":"Hazabe","height":"213","width":"320","class":"media-element file-story-image-left"}}]]

As long the url part of field_photo is empty it is displayed like wanted.
When I enter there a URL the entire picture with caption text disappears from the output.
I have actual no clue where to check why the URL is filtered out.
Help or hints are appreciated.

alimc29’s picture

Just adding a comment here to hopefully help anyone who might need it - CKEditor ACF - http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter - also has a disallowedContent setting.

We tried the other suggestions for one of our sites, but its configuration was so complex that was creating issues - specifically because we were using the ckeditor_image2 module and needed it to be able to control left/center/right alignment and captions, but we were also trying to work with media_youtube, and our videos would not work without $settings['allowedContent'] = TRUE;, but this created issues for the ckeditor_image2 integration, and I couldn't figure out the proper tag to use for the videos inserted via media_wysiwyg/media_youtube combination.

Because we wanted to be able to use the media tokens, but allow the user to control the image properties via the wysiwyg, we ended up with the following:

<?php
/**
* Implements hook_wysiwyg_editor_settings_alter().
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['allowedContent'] = TRUE;
    $settings['disallowedContent'] = array(
      'img',
    );
  }
}
?>
fadeslayer’s picture

I have replied to this (https://www.drupal.org/node/1965536#comment-11543537) which seems related to this one.

joseph.olstad’s picture

#27 works for me
didn't require any custom module either, just added the settings
img[title,alt,src,data-cke-saved-src](wysiwyg-break,drupal-content);video[width,height,controls,src](*);source[src,type];audio[controls,src](*);img[*](media-element,file-default)
to the Cleanup and Output 'Content Rules'
/admin/config/content/wysiwyg/profile/editor

and because our client wants to preserve font styles in paste from word items , precede this with properties;
so:
properties;img[title,alt,src,data-cke-saved-src](wysiwyg-break,drupal-content);video[width,height,controls,src](*);source[src,type];audio[controls,src](*);img[*](media-element,file-default)
works as well.

ACF configuration is important because in ckeditor >=4.6.x ACF configuration is required for the paste from word plugin to work properly (or paste from LibreOffice ). The ACF must be configured correctly because the paste from word plugin relies on ACF. However if ACF is not correctly configured the media browser in wysiwyg will not work correctly.