【问题标题】:How to add a custom text to a field (translatable) label如何将自定义文本添加到字段(可翻译)标签
【发布时间】:2021-11-17 11:59:40
【问题描述】:

我有一个带有本地化字段数据的对象:

我想为我的 DataObject 自定义后端 UI,因为这是不可能的,只有一种语言需要该字段。

我知道,如何检查 PHP 事件侦听器中的强制项,但我找不到任何信息,如何仅在德语字段标签中添加星号。

这是我的 JS:

pimcore.registerNS('pimcore.test.plugin');

pimcore.test.plugin = Class.create(pimcore.plugin.admin, {
    getClassName: function () {
        return 'pimcore.test.plugin';
    },

    pimcoreReady: function (params,broker) {
    },

    initialize: function () {
        pimcore.plugin.broker.registerPlugin(this);
    },

    postOpenObject: function (object, type) {
        if (object.data.general.o_className === 'Product') {
            // add an asterisk to field label
        }
    },
});

let PimcoreTestPlugin = new pimcore.test.plugin();

更新 1:我在 Pimcore Sources 中找到了在任何字段中添加星号(如果需要字段)的部分,但我如何扩展/覆盖它们?

pimcore.registerNS("pimcore.object.helpers.edit");
pimcore.object.helpers.edit = {

    getRecursiveLayout: function (l, noteditable, context, skipLayoutChildren, onlyLayoutChildren, dataProvider, disableLazyRendering) {
        ...

        // add asterisk to mandatory field
        l.titleOriginal = l.title;
        if(l.mandatory) {
            l.title += ' <span style="color:red;">*</span>';
        }

        ...
    }
};

【问题讨论】:

    标签: extjs pimcore


    【解决方案1】:

    我不知道如何使用 PimCore,但解决方案是使用数据绑定:

    现代

    items: [{
        xtype: 'textfield',
        fieldLabel: 'Name',
        bind: {required: '{isGerman}'}
    }]
    

    在经典中

    Ext.define('MyApp.overrides.form.field.Text', {
        override: 'Ext.form.field.Text',
    
        config: {
            allowBlank: true
        }
    });
    
    ...
    items: [{
        xtype: 'textfield',
        fieldLabel: 'Name',
        bind: {allowBlank: '{!isGerman}'}
    }]
    

    如果 allowBlank|required 将添加星号。

    • required 如果为真,将添加星号。允许
    • 如果为 false,Blank 将添加星号。

    【讨论】:

    • 感谢您的回答。但我不确定它是否对我有帮助...我在 Pimcore 包中找到了一个添加星号的部分,但我不知道如何扩展/覆盖它们...
    • 那就是l.mandatory &amp;&amp; langsetting.de
    • 但是如何从 pimcore 扩展这个助手呢?
    • 由于您没有发布如何阅读语言设置,因此无法提供任何进一步的帮助。可能是上下文包含当前语言,但我无法判断,没有更多信息。
    【解决方案2】:

    您可以创建自定义数据类型,在其中指定允许编辑的语言/应该显示的语言。在 Pimcore 中,这是通过后端的 CoreExtensions 和 JS 中的自定义数据标签来完成的。

    https://pimcore.com/docs/pimcore/current/Development_Documentation/Extending_Pimcore/Bundle_Developers_Guide/Adding_Object_Datatypes.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      • 2012-03-25
      相关资源
      最近更新 更多