组/字段集之间的system.xml依赖项


12

system.xml允许我们根据其他字段的值来使各个字段可见。goto文章当然来自Alan Storm:《深度Magento系统配置》

看起来像这样(我在这里借用他的示例代码):

Location: app/code/local/Alanstormdotcom/Helloworld/etc/system.xml

<config>
<tabs>
    <helloconfig translate="label" module="helloworld">
        <label>Hello Config</label>
        <sort_order>99999</sort_order>
    </helloconfig>
</tabs>
<sections>
    <helloworld_options translate="label" module="helloworld">
        <label>Hello World Config Options</label>
        <tab>helloconfig</tab>
        <frontend_type>text</frontend_type>
        <sort_order>1000</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <notes translate="label">
                <label>Demo Of Config Fields NOTES</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <enabled translate="label">
                        <label>Enabled</label>
                        <frontend_type>select</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </enabled>
                    <hello_note>
                        <label>Message</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>2</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                        <depends>
                            <enabled>1</enabled>
                        </depends>
                    </hello_note>
                </fields>
            </notes>
            <messages translate="label">
                <label>Demo Of Config Fields MESSAGES</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <hello_message>
                        <label>Message</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </hello_message>
                    <hello_time>
                        <label>Time to Say Hello</label>
                        <frontend_type>time</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </hello_time>
                </fields>
            </messages>
        </groups>
    </helloworld_options>
</sections>

由于这似乎只与同组/字段(内场工作<notes>在这个例子中),我想知道:有没有一种方法,使<hello_message><messages>组依赖于<enabled><notes>组?

Answers:


10

咨询了适当的核心文件之后,跨组/字段集<depends>如下所示:

<!-- … -->
<hello_message>
    <label>Message</label>
    <frontend_type>text</frontend_type>
    <sort_order>1</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <depends>
        <enabled>
            <fieldset>notes</fieldset>
            <value>1</value>
        </enabled>
    </depends>
</hello_message>
<!-- … -->
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.