首页 > 解决方案 > Pimcore 在对象编辑器中将按钮添加到面板

问题描述

我想在我自己的对象编辑器的面板中添加一个按钮。我成功地在对象编辑器中添加了一个图标和处理程序,就像示例文档中一样。但是我想在编辑器下方的面板中的某处添加一个按钮。如何找出要扩展的 js 文件,以便创建菜单按钮。

https://talk.pimcore.org/uploads/default/optimized/2X/7/725a347773479a7136600daeee66d7883ed19ae7_2_487x500.png

我试图扩展对象类,我想知道执行哪个函数来将我的按钮添加到这个工具栏

`pimcore.plugin.celumImage = Class.create(pimcore.plugin.admin, {
 postOpenObject: function (object, type) {
        console.log("dsdsd"+object.data.general.o_className);
            object.toolbar.add({
                text: t('show-pdf'),
                iconCls: 'pimcore_icon_pdf',
                scale: 'small',
                handler: function (obj) {
                    //do some stuff here, e.g. open a new window with an PDF download
                }.bind(this, object)
            });
            pimcore.layout.refresh();
    },
});`

你能在这里得到标签面板还是我应该扩展对象类以便我可以在图像中添加按钮

标签: pimcore

解决方案


由于您没有发布完整的类定义,我只能估计 javascript 应该是什么样子。如果您只有一个简单的 tabpabel,则可以使用以下内容:

postOpenObject: function (object, type) {
    object.tabPanel
        .getComponent(0) // get object tab
        .getComponent(1) // get edit tabpanel
        .getComponent(0) // get class tab
        .getComponent(3) // get fourth tab in class tabpanel
        .query("*[componentCls~=object_field]")[0] // get first panel with class "object_field" - could be replaced with down(...)
        .getDockedComponent(0) // get toolbar
        .add({
            text: t('show-pdf'),
            iconCls: 'pimcore_icon_pdf',
            scale: 'small',
            handler: function (obj) {
                //do some stuff here, e.g. open a new window with an PDF download
            }.bind(this, object)
        });
})

根据数据对象的布局有多复杂(或将有多复杂),您可以删除getComponent()调用并直接down()调用对象标签。

如果您更改类的布局,请确保调整代码,如果需要,如果您为每个布局使用自定义布局,请考虑调整上面的代码。

您也可以查看Panel 组件的 Ext.js 文档,只需搜索被调用的方法。


推荐阅读