是否可以在 AEM 组件的工具栏上添加自定义按钮?

Is it possible to add a custom button on a toolbar of a component on AEM?

在AEM 6.5的编辑模式下,如果我点击一个组件,会弹出上面的工具栏。除了通过在 CRXDE 上创建 cq:dialog 节点来添加对话框(扳手按钮)之外,您可以在工具栏上创建自定义按钮吗?如果是这样,我可以在网上找到哪些工作示例?

是的,你可以这样做。

您将需要使用在工具栏中注册按钮的 JS 文件创建自定义客户端库:

(function ($document, author) {
    var openDialog = {
        icon: 'coral-Icon--game',
        text: 'Open Dialog',
        handler: function (editable, param, target) {
            author.DialogFrame.openDialog(new author.edit.Dialog(editable));
        },
        condition: function (editable) {
            //show this action only for component type eaem-touchui-open-comp-dialog-register-action/touchui-open-component-dialog
            return editable.type === "eaem-touchui-open-comp-dialog-register-action/touchui-open-component-dialog";
        },
        isNonMulti: true
    };

    $document.on('cq-layer-activated', function (ev) {
        if (ev.layer === 'Edit') {
            author.EditorFrame.editableToolbar.registerAction('EAEM_OPEN_DIALOG', openDialog);
        }
    });
})($(document), Granite.author);

您可以自定义按钮的图标、文本和行为,并决定此工具栏自定义对哪些组件可见。

source