Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Not able to add new button on ckeditor
Hi,
I am trying to add a new button on ckeditor in Liferay 7.1. I am following the article. I am not getting any error, however the button is also not visible in toolbar.
Attaching code snippet.
If someone has implemented similar functionality in 7.1, please provide the steps that was followed in order to get it working.
Thanks.
Added LiferaySnippetbrowser class to extend BaseEditorConfigContributor and override populateConfigJSONObject method as below:
And
The same code works if I configure default WYSIWYG editor as alloyeditor.
I am trying to add a new button on ckeditor in Liferay 7.1. I am following the article. I am not getting any error, however the button is also not visible in toolbar.
Attaching code snippet.
If someone has implemented similar functionality in 7.1, please provide the steps that was followed in order to get it working.
Thanks.
Added LiferaySnippetbrowser class to extend BaseEditorConfigContributor and override populateConfigJSONObject method as below:
@Component(
property = {"editor.name=alloyeditor", "editor.name=ckeditor",
"service.ranking:Integer=100"},
service = EditorConfigContributor.class
)
public class LiferaySnippetbrowser extends BaseEditorConfigContributor {
@Override
public void populateConfigJSONObject(JSONObject jsonObject, Map<string, object> inputEditorTaglibAttributes,
ThemeDisplay themeDisplay, RequestBackedPortletURLFactory requestBackedPortletURLFactory) {
JSONArray toolbars = jsonObject.getJSONArray("toolbar_tablet");
if (toolbars != null) {
JSONArray addButtons = JSONFactoryUtil.createJSONArray();
addButtons.put("camera");
toolbars.put(addButtons);
jsonObject.put("toolbar_tablet", toolbars);
}else if(jsonObject.getJSONObject("toolbars") != null){
JSONObject toolbar1 = jsonObject.getJSONObject("toolbars");
if (toolbar1 != null) {
JSONObject toolbarAdd = toolbar1.getJSONObject("add");
if (toolbarAdd != null) {
JSONArray addButtons = toolbarAdd.getJSONArray("buttons");
addButtons.put("camera");
}
}
}
else{
JSONArray addButtons = JSONFactoryUtil.createJSONArray();
addButtons.put("camera");
jsonObject.put("liferay_add", addButtons);
}
}
}</string,>
And
@Component(immediate = true, service = DynamicInclude.class)
public class AlloyEditorMyButtonDynamicInclude extends BaseDynamicInclude {
@Override
public void include(
HttpServletRequest request, HttpServletResponse response,
String key)
throws IOException {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
PrintWriter printWriter = response.getWriter();
StringBundler sb = new StringBundler(7);
sb.append("<script src="\"");" sb.append(themedisplay.getportalurl()); sb.append(portalutil.getpathproxy()); sb.append(_servletcontext.getcontextpath()); sb.append(" js buttons.js"); sb.append("\" "); sb.append("type="\"text/javascript\""></script>");
printWriter.println(sb.toString());
}
@Override
public void register(DynamicIncludeRegistry dynamicIncludeRegistry) {
dynamicIncludeRegistry.register(
"com.liferay.frontend.editor.alloyeditor.web#ckeditor#" +
"additionalResources");
}
@Reference(
target = "(osgi.web.symbolicname=com.liferay.frontend.editor.ckeditor.my.button.web)"
)
private ServletContext _servletContext;
}
The same code works if I configure default WYSIWYG editor as alloyeditor.
No reply yet. Has anybody tried this?
Hi Vipul
if you share a repository of this project in github, anyone can help you better.
i was added some buttons in jira editor and i hope this could help you.
if you share a repository of this project in github, anyone can help you better.
i was added some buttons in jira editor and i hope this could help you.
@Vipul Khatavkar some time has passed, did you solve your problem? I have the same issue with Language plugin for CKEditor. It doesn't want to work in Liferay 7.2.1 (button doesn't appear), but when I do exactly same things in CKEditor out of Liferay it works perfectly.
Liferay should be taking and implementing feature requests for the editor development. I guarantee what you're trying to do someone else is trying to do also and we should not have to customize such a core feature.
Hi Vipul,
Adding a button to the toolbar works a bit different because of the structure of the JSON object. There is no such thing (anymore, or only in Liferay's CK Editor config) as different *named* sets of buttons. It's just a multi dimensional array of button names. If you output the JSONObject before trying to add the button, you'll that it looks something like:
So the way to add a button here (without checking array boundaries etc.) is:
Adding a button to the toolbar works a bit different because of the structure of the JSON object. There is no such thing (anymore, or only in Liferay's CK Editor config) as different *named* sets of buttons. It's just a multi dimensional array of button names. If you output the JSONObject before trying to add the button, you'll that it looks something like:
[
["Bold","Italic","Underline","Strike","-","Subscript","Superscript","-","RemoveFormat"],
["TextColor","BGColor"],
["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
["NumberedList","BulletedList","-","Outdent","Indent"],
"/",
["Styles","FontSize"],
["Link","Unlink","Anchor"],
["Table","-","ImageSelector","Flash","-","Smiley","SpecialChar"],
"/",
["Cut","Copy","Paste","-","PasteText","PasteFromWord","-","SelectAll","-","Undo","Redo"],
["Find","Replace","-","SpellChecker","Scayt"],
["Source"],["A11YBtn"]
]
So the way to add a button here (without checking array boundaries etc.) is:
JSONArray toolbars = jsonObject.getJSONArray("toolbar_liferay");
JSONArray buttons = toolbars.getJSONArray(9);
buttons.put("-");
buttons.put("Timestamp");
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™