Add Alloy Editor buttons for fragments with text

Issue

  • Trying to new buttons to Alloy Editor in fragments with text is not working.
  • What should be the appropriate editor's configuration?

Environment

  • Liferay DXP 7.2, 7.3

Resolution

  • The documentation articles Adding a Button to the Add Toolbar and Adding a Button to a Styles Toolbar explain how to add particular buttons for the Add and Styles Toolbars.
  • The documentation article Modifying an Editor's Configuration explains how to target particular portlets and editors.
  • To make sure that the changes affect fragments with text it's necessary to specify the appropriate editor.config.key and javax.portlet.name:
    @Component(
    immediate = true,
    property = {
    "editor.config.key=fragmenEntryLinkRichTextEditor",
    "javax.portlet.name=" + ContentPageEditorPortletKeys.CONTENT_PAGE_EDITOR_PORTLET,
    "service.ranking:Integer=100"
    },
    service = EditorConfigContributor.class
    )
  • Note that the Add Toolbar "+" button will appear by default on the left of the text box, so it might be hidden if the fragment stretches all the way to the left. It's possible to change the button position, for example to the right, with:
    JSONObject toolbarsJSONObject = jsonObject.getJSONObject("toolbars");
    
    JSONObject addToolbar = toolbarsJSONObject.getJSONObject("add");
    
    addToolbar.put("position", "right");
这篇文章有帮助吗?
0 人中有 0 人觉得有帮助