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?

asked Aug 7, 2017 at 20:00
1
  • how to set validation for above fields in system.xml Commented Feb 13, 2018 at 7:06

1 Answer 1

0

Write default value to database in data install script.

answered Aug 8, 2017 at 6:51
1
  • I wanted to avoid that solution, but I didn't manage to find any other solution. Thanks! ;) Commented Aug 11, 2017 at 19:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.