Magento 2:system.xml中的可用字段类型


26

etc/system.xml配置文件中字段类型的可用值是什么:

<?xml version="1.0"?>
<config
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="...">
            <group id="...">
                <field id="..." type="???">
                    ...
                </field>
            </group>
        </section>
    </system>
</config>

Answers:


44

Magento 2系统配置提供以下字段类型。

checkbox,
checkboxes,
column,
date,
editablemultiselect,
editor,
fieldset,
file,
gallery,
hidden,
image,
imagefile,
label,
link,
multiline,
multiselect,
note,
obscure,
password,
radio,
radios,
reset,
select,
submit,
text,
textarea,
time

标签不起作用
— Zorox

关于如何用绿色/灰色使是/否按钮有任何想法吗?
— Zeeshan Khuwaja

@ZeeshanKhuwaja和未来的人,这不链接到Q,但是您想将<source_model> Magento \ Config \ Model \ Config \ Source \ Yesno </ source_model>附加到您的字段
— John

15

纵观文件/lib/internal/Magento/Framework/Data/Form/Element/Factory.php(找到这里 Github上,对于Magento的2.2&2.3),人们可以找到的元素下面的默认列表,如由阿米特中指定他的回答:

// Factory.php, lines 26-55
protected $_standardTypes = [
    'button',
    'checkbox',
    'checkboxes',
    'column',
    'date',
    'editablemultiselect',
    'editor',
    'fieldset',
    'file',
    'gallery',
    'hidden',
    'image',
    'imagefile',
    'label',
    'link',
    'multiline',
    'multiselect',
    'note',
    'obscure',
    'password',
    'radio',
    'radios',
    'reset',
    'select',
    'submit',
    'text',
    'textarea',
    'time',
];

如果使用Composer安装Magento,则也可以在中找到数据/vendor/magento/framework/Data/Form/Element/Factory.php,如下面Mohit的评论中所述。


2
我很抱歉添加一个新答案,而不是评论Amit的答案。在发布此答案时,我没有足够的声誉来评论他人的答案。
— RNanoware

我认为您已经通过添加工厂文件详细信息来完成了Amit的回答。为此投票。
— Mohit Kumar Arora

3
但是我的Magento 2.2.3没有这样的路径。我可以在/vendor/magento/framework/Data/Form/Element/Factory.php路径中找到Factory.php文件。
— Mohit Kumar Arora

2
@MohitKumarArora你是对的!我认为,不同的文件路径与Magento的安装方式有关:从Git克隆似乎使用/lib/internal,而已知Composer会创建该/vendor文件夹。我将相应地更新答案。谢谢!
— RNanoware

任何人都可以使用sorce模型添加/解释字段类型吗,就像yesno一样具有源模型Magento / config / model / config / source / yesno
— nagendra
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.