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.xmlJaisa– Jaisa2018年02月13日 07:06:22 +00:00Commented Feb 13, 2018 at 7:06
1 Answer 1
Write default value to database in data install script.
-
I wanted to avoid that solution, but I didn't manage to find any other solution. Thanks! ;)Jan Petr– Jan Petr2017年08月11日 19:17:26 +00:00Commented Aug 11, 2017 at 19:17
Explore related questions
See similar questions with these tags.