1

I have a custom extension which adds new inputs to Magento's configuration. Some of the inputs are arrayFields and its defined in system.xml file as:

<field id="custom_ranking_product_attributes" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Ranking</label>
    <frontend_model>My\CustomModule\Model\Source\CustomRankingProduct</frontend_model>
    <backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
    <comment>
        <![CDATA[ Some comment ]]>
    </comment>
</field>

Class My\CustomModule\Model\Source\CustomRankingProduct is a child of Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray.

In config.xml file I have defined a default value for this input like:

<custom_ranking_product_attributes>a:1:{s:18:"_1427960305274_274";a:2:{s:9:"attribute";s:11:"ordered_qty";s:5:"order";s:4:"desc";}}</custom_ranking_product_attributes>

In Magento 2.0.* I can see the default value filled to the input: With default value

But in Magento 2.1.* it's empty: No default value

However, when I try to get the config value, the correct array is returned in both 2.0.* and 2.1.. Just 2.1. doesn't display the default value so after the initial configuration save it becomes empty.

What can I do to have the default value correctly displayed even in Magento 2.1?

  • how to set validation for above fields in system.xml – Jaisa Feb 13 '18 at 7:06
0

Write default value to database in data install script.

| improve this answer | |
  • I wanted to avoid that solution, but I didn't manage to find any other solution. Thanks! ;) – Jan Petr Aug 11 '17 at 19:17

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.