Not able to add new button on ckeditorNot able to add new button on ckeditorhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1124043002024-03-29T05:35:43Z2024-03-29T05:35:43ZRE: Not able to add new button on ckeditorGeert van der Ploeghttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1198276022020-08-24T08:02:54Z2020-08-24T08:02:54Z<html><head></head><body>Hi Vipul,<br>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:<br><pre><code>[
&nbsp;&nbsp; &nbsp;["Bold","Italic","Underline","Strike","-","Subscript","Superscript","-","RemoveFormat"],
&nbsp;&nbsp; &nbsp;["TextColor","BGColor"],
&nbsp;&nbsp; &nbsp;["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
&nbsp;&nbsp; &nbsp;["NumberedList","BulletedList","-","Outdent","Indent"],
&nbsp;&nbsp; &nbsp;"/",
&nbsp; &nbsp; ["Styles","FontSize"],
&nbsp; &nbsp; ["Link","Unlink","Anchor"],
&nbsp; &nbsp; ["Table","-","ImageSelector","Flash","-","Smiley","SpecialChar"],
&nbsp; &nbsp; "/",
&nbsp; &nbsp; ["Cut","Copy","Paste","-","PasteText","PasteFromWord","-","SelectAll","-","Undo","Redo"],
&nbsp; &nbsp; ["Find","Replace","-","SpellChecker","Scayt"],
&nbsp; &nbsp; ["Source"],["A11YBtn"]
]</code></pre><br>So the way to add a button here (without checking array boundaries etc.) is:<br><pre><code>&nbsp; &nbsp; &nbsp; &nbsp; JSONArray toolbars = jsonObject.getJSONArray("toolbar_liferay");
&nbsp; &nbsp; &nbsp; &nbsp; JSONArray buttons = toolbars.getJSONArray(9);
&nbsp; &nbsp; &nbsp; &nbsp; buttons.put("-");
&nbsp; &nbsp; &nbsp; &nbsp; buttons.put("Timestamp");</code></pre><span style="color: #e83e8c"><span style="font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace"><span style="font-size: 14px;"></span></span></span></body></html>Geert van der Ploeg2020-08-24T08:02:54ZRE: Not able to add new button on ckeditorLee Jordanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1185906202020-02-25T20:08:49Z2020-02-25T20:08:49ZLiferay 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.Lee Jordan2020-02-25T20:08:49ZRE: Not able to add new button on ckeditorMarcin Pawlukhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1185886792020-02-25T19:10:47Z2020-02-25T19:10:47Z@<strong>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.</strong>Marcin Pawluk2020-02-25T19:10:47ZRE: Not able to add new button on ckeditorNader Jafarihttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1127494842019-03-14T10:49:37Z2019-03-14T10:49:37ZHi Vipul <br />if you share a repository of this project in github, anyone can help you better.<br />i was added some buttons in jira editor and i hope this could help you.Nader Jafari2019-03-14T10:49:37ZRE: Not able to add new button on ckeditorVipul Khatavkarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1127447512019-03-14T09:55:27Z2019-03-14T09:55:27ZNo reply yet. Has anybody tried this?Vipul Khatavkar2019-03-14T09:55:27ZNot able to add new button on ckeditorVipul Khatavkarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1124042992019-02-20T03:38:59Z2019-02-20T03:38:59Z<html><head></head><body>Hi,<br><br>I am trying to add a new button on ckeditor in Liferay 7.1. I am following the <a href="https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-0/modifying-an-editors-configuration">article</a>. I am not getting any error, however the button is also not visible in toolbar.<br><br>Attaching code snippet.<br><br>If someone has implemented similar functionality in 7.1, please provide the steps that was followed in order to get it working.<br><br>Thanks.<br><br>Added LiferaySnippetbrowser class to extend BaseEditorConfigContributor and override populateConfigJSONObject method as below:<pre><code>@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,></code></pre><br>And <br><pre><code>@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="\&quot;&quot;);" sb.append(themedisplay.getportalurl()); sb.append(portalutil.getpathproxy()); sb.append(_servletcontext.getcontextpath()); sb.append(" js buttons.js"); sb.append("\" "); sb.append("type="\&quot;text/javascript\&quot;"></script>");
printWriter.println(sb.toString());
}
@Override
public void register(DynamicIncludeRegistry dynamicIncludeRegistry) {
dynamicIncludeRegistry.register(
"com.liferay.frontend.editor.alloyeditor.web#ckeditor#" +
"additionalResources");