Issue
- Business needs may sometimes require to customize the AlloyEditor hyperlink dropdown list in the AlloyEditor toolbar:
Environment
- Liferay DXP 7.2
Resolution
You can provide additional configuration to the link dropdown list. The best approach to do it is creating an EditorConfigContributor passing the buttonCfg:
buttonCfg: {
'linkEdit': {
allowedTargets: [
{
label: AlloyEditor.Strings.linkTargetDefault,
value: ''
}, {
label: AlloyEditor.Strings.linkTargetBlank,
value: '_blank'
}
]
}
This is somehow similar to what we are already doing in AlloyEditorCreoleEditorConfigContributor.java. So in the end, the cleanest solution is just adding below code into populateConfigJSONObject method:
JSONArray allowedTargetsJSONObject = JSONUtil.putAll(
JSONUtil.put("label","_self (same tab)").put("value","_self"),
JSONUtil.put("label","_blank (new tab)").put("value","_blank")
);
JSONObject linkEditJSONObject = JSONUtil.put(
"allowedTargets", allowedTargetsJSONObject
);
JSONObject buttonCfgJSONObject = JSONUtil.put(
"linkEdit", linkEditJSONObject);
jsonObject.put(
"buttonCfg", buttonCfgJSONObject
);
Attached, a small plugin demonstrating the new behavior.