How to Build a Food...
December 18, 2024
Integrate Media Embed and IFrame plugins in CKEditor to add any type of media and IFrame support in editor.
As we know, Liferay 7 provides different WYSIWYG editors the portal. In this article we will modify the CKEditor plugins configurations.
By default, on Liferay 7 fresh setup AlloyEditor is available in the portal. We can change to CKEditor by setting following properties in porta-exp.properties file for different portlets.
editor.wysiwyg.default=ckeditor
editor.wysiwyg.default=ckeditor
editor.wysiwyg.portal-impl.portlet.ddm.text_html.ftl=ckeditor
editor.wysiwyg.portal-web.docroot.html.portlet.blogs.edit_entry.jsp=ckeditor
editor.wysiwyg.portal-web.docroot.html.portlet.journal.edit_article_content.jsp=ckeditor
Now, we will integrate Media Embed and IFrame plugins which are not available in CKEditor by default in Liferay Portal.
if (jsonObject.has("extraPlugins")) {
String extraPlugins = jsonObject.getString("extraPlugins");
if (!extraPlugins.contains("widget")) {
extraPlugins += ",widget";
}
if (!extraPlugins.contains("embed")) {
extraPlugins += ",embed";
}
if (!extraPlugins.contains("autoembed")) {
extraPlugins += ",autoembed";
}
if (!extraPlugins.contains("iframe")) {
extraPlugins += ",iframe";
}
jsonObject.put("extraPlugins", extraPlugins);
}
if (jsonObject.has("allowedContent")) {
String allowedContent = jsonObject.getString("allowedContent");
allowedContent += "div[!data-oembed-url];iframe[align,longdesc,frameborder,height,name,scrolling,src,title,width];";
jsonObject.put("allowedContent", allowedContent);
}
jsonObject.put("autoEmbed_widget", "embed,embedSemantic");
jsonObject.put("embed_provider", "//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}");
JSONArray toolbarsLiferay = null;
JSONArray extraTools_liferay = JSONFactoryUtil.createJSONArray();
if (jsonObject.has("toolbar_liferay")) {
toolbarsLiferay = jsonObject.getJSONArray("toolbar_liferay");
extraTools_liferay = toolbarsLiferay.getJSONArray(7);
}
extraTools_liferay.put("-");
extraTools_liferay.put("Embed");
extraTools_liferay.put("Iframe");
if (Validator.isNull(toolbarsLiferay)) {
toolbarsLiferay = JSONFactoryUtil.createJSONArray();
toolbarsLiferay.put(extraTools_liferay);
}
I have done steps to add Media Embed icon in the toolbar for Desktop screens. Same way we can add Media Embed icon for tables and phone screens by adding Embed and Iframe in toolbar_table and toolbar_phone JSON.
INEXTURE known as leading Liferay consulting services provider in India, deliver the best in class solutions that improve the effectiveness and efficiency of the product. Our highly experienced team provides crucial process backbone and framework for every product and this will enable instant and collaborative application development.