6
Magento 2のモジュール構成にsystem.xml
ファイルを追加することはできますか?もしそうなら、どうですか?Magento 2:カスタムモジュールのsystem.xml
Magento 2のモジュール構成にsystem.xml
ファイルを追加することはできますか?もしそうなら、どうですか?Magento 2:カスタムモジュールのsystem.xml
はい、Magento 2では、Magento 1.xと同じシステム構成ファイルを作成できます。しかし、他のファイルを作成する必要があります。
作成するには、次のファイルを使用する必要があります。
1) app/code/Vendor/Helloworld/etc/adminhtml/system.xml
2) app/code/Vendor/Helloworld/etc/acl.xml
この2つのファイルは、システム構成を作成するために重要です。 acl.xml
ファイル
で
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>
ファイルには、以下のコンテンツその後
<?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>
を記述する必要がある、クリアインクルードマゼンタキャッシュ&管理者側からのログアウト。その後、管理者側でログインします。 [Store]> [Configuration]で、[Vendor Extension]タブが表示されます。これをクリックすると、これの詳細を見ることができます。
"section"要素内の "group"要素を移動したときに完全に機能しました。それ以外の場合は、system.xmlでエラーが発生しました。 – Gerard