Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ckeditor doesn´t read media embed code

Tags:

I use the media embed plugin for ckeditor. It works fine, the code is correctly saved in the database and youtube, soundcloud etd. players display ok on the page. But when the user goes to his administration, where he can edit the info, the text inside and with the tags is not showing, so when the user clicks on the save button, all previously saved iframes will be "erased" and only the rest of the formatted text will be saved. Is there any way to display the iframe code in the ckeditor?

like image 534
Michal S Avatar asked Jun 07 '13 03:06

Michal S


People also ask

How do I upload a youtube video to CKEditor?

This plugin allows inserting Youtube videos using embed code or just the video URL. Follow these steps: Extract the downloaded file into the CKEditor's plugins folder. Enable the plugin by changing or adding the extraPlugins line in your configuration (config.

What can I do with CKEditor?

The “WYSIWYG” part means that when you use CKEditor 4, you can style the text and add rich media contents to your document in real time by using the editor UI (toolbar buttons, dialog windows), and the result will be seen immediately.


2 Answers

I assume that you use CKEditor 4.1.x which comes with Advanced Content Filter (ACF). Most likely, the point is that you use different editors for frontend/backend editing.

Each plugin extends allowedContent property with own rules for tags, attributes and classes. Using those rules, editor automatically strips out undesired contents, so for example, if your fronted editor allows <iframe> because it has mediaembed plugin loaded, then your backend editor without this plugin will remove your <iframe> from the content.

Furthermore, ACF also observes your toolbar configuration so even if you include the plugin but you don't want the button in the toolbar, any content the button provides (i.e. <iframe>) will also be disallowed in editor's output.

You can easily check whether your editor accept <iframes>. Basically call the following and see the output:

CKEDITOR.instances.yourInstance.filter.check( 'iframe' );
>>> true // it's allowed

If it's false, then there are several solutions for your problem:

  1. Enable mediaembed plugin in your backend editor (with button in the toolbar).
  2. Extend config.extraAllowedContent to have it back again.

While the first solution is straightforward, the second one might be tricky for you. allowedContent rule for mediaembed plugin is as follows (see plugin's code):

allowedContent: 'iframe[*]' // stands for: iframe element with any attribute

If you add the following to your backend editor's config, you will have iframes back in your content without loading mediaembed plugin:

config.extraAllowedContent = 'iframe[*]'

If this solution doesn't work for you, please provide editor configs and CKEditor version so that people could help you.

like image 171
oleq Avatar answered Oct 26 '22 22:10

oleq


CKEDITOR.config.allowedContent = true;

work for me.

like image 34
gokhan Avatar answered Oct 26 '22 21:10

gokhan