1

Hi I am new to magento2 and learning currently the basics.

I have an module and set up some system configuration for it but the checkbox Use system value is not showing up next to the field. I have setup a default value for it in config.xml. I am using magento-ce 2.2.5

Expected: enter image description here

Actual: enter image description here

Here is my 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>
   <tab id="mastering" translate="label" sortOrder="10000">
        <label>Mastering</label>
    </tab>
    <section id="mastering" translate="label" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>Mastering</label>
        <tab>mastering</tab>
        <resource>Mastering_SampleModule::mastering</resource>
        <group id="general" translate="label" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
            <label>Item creation by schedule</label>
            <field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Enabled</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>
            <field id="cron_expression" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Add Item Cron Expression</label>
            </field>
        </group>
    </section>
</system>

My config.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
    <mastering>
        <general>
            <enabled>0</enabled>
            <cron_expression>* * * * *</cron_expression>
        </general>
    </mastering>
</default>

1 Answer 1

3

I believe the trick to having that checkbox is to add the canRestore="1" attribute to your config option. i.e.

<?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>
   <tab id="mastering" translate="label" sortOrder="10000">
        <label>Mastering</label>
    </tab>
    <section id="mastering" translate="label" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>Mastering</label>
        <tab>mastering</tab>
        <resource>Mastering_SampleModule::mastering</resource>
        <group id="general" translate="label" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
            <label>Item creation by schedule</label>
            <field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Enabled</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>
            <field id="cron_expression" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                <label>Add Item Cron Expression</label>
            </field>
        </group>
    </section>
</system>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.