首页 > 解决方案 > 如何将自定义文本添加到字段(可翻译)标签

问题描述

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

在此处输入图像描述

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

我知道,我如何检查 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>';
        }

        ...
    }
};

标签: extjspimcore

解决方案


我不知道如何使用 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,空白将添加星号。

推荐阅读