6

system.xmlMagento 2 でモジュール構成用のファイルを追加することは可能ですか? もしそうなら、どのように?

4

1 に答える 1

13

はい、magento 2 では、Magento 1.x と同じシステム構成ファイルを作成できます。ただし、他のファイルを作成する必要があります。

作成するには、次のファイルを使用する必要があります。

1) app/code/Vendor/Helloworld/etc/adminhtml/system.xml

2) app/code/Vendor/Helloworld/etc/acl.xml

この 2 つのファイルは、システム構成を作成するために重要です。

ファイルsystem.xml

共通コンテンツの追加

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
    <system>
        <!-- Add new Tab -->
        <tab id="vendor" translate="label" sortOrder="300">
            <label>Vendor Extension</label>
        </tab>
        <section id="helloworld" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Helloworld</label>
            <tab>vendor</tab>
            <!-- resource tag name which we have to defined in the acl.xml -->
            <resource>Vendor_Helloworld::config_helloworld</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General Options</label>
                <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

ファイルacl.xml

ファイルに以下の内容を書き込む必要があります

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">
                            <!-- this resource id we can use in system.xml for section -->
                            <resource id="Vendor_Helloworld::config_helloworld" title="Helloworld Section" sortOrder="80" />
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

その後、magento キャッシュをクリアして、管理者側からログアウトします。次に、管理者側でログインします。ストア > 構成では、「ベンダー拡張」タブが表示されます。これをクリックすると、この詳細が表示されます。

于 2015-09-16T17:07:46.473 に答える