10

According magento 1, we extend from "adminhtml/system_config_backend_serialized_array" to create a table like this : enter image description here

My question is : How we create it in magento 2 ?

Edit: Finally, with @Marius help : it's User-Agent Exceptions field in System=>Configuration=>General=>Design=>Design Theme.

enter image description here

We can create a new table configuration based on this field by looking at it's codes "Magento\Config\Block\System\Config\Form\Field\Regexceptions"

asked Dec 22, 2015 at 8:09
2
  • look into this magento.stackexchange.com/questions/86147/… it will help out Commented Dec 22, 2015 at 8:39
  • Thank you. But I think the answer from @Marius is what I need. Commented Dec 23, 2015 at 4:32

2 Answers 2

17

You can do it using, Company/Modulename/etc/adminhtml/system.xml

Under section -> group field

<field id="mapping" translate="label comment tooltip" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
 <label>Customer Fields Mapping</label>
 <frontend_model>Company\Modulename\Block\Adminhtml\System\Config\Form\Field\Customermap</frontend_model>
 <backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
 <comment>
 <![CDATA[Add the comments!]]>
 </comment>
 <tooltip>Map the magento customer field to custom module merge_fields</tooltip>
</field>

In frontend model file inside block,

<?php
namespace Company\Modulename\Block\Adminhtml\System\Config\Form\Field;
class Customermap extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
 /**
 * @var \Magento\Framework\Data\Form\Element\Factory
 */
 protected $_elementFactory;
 /**
 * @param \Magento\Backend\Block\Template\Context $context
 * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
 * @param array $data
 */
 public function __construct(
 \Magento\Backend\Block\Template\Context $context,
 \Magento\Framework\Data\Form\Element\Factory $elementFactory,
 array $data = []
 )
 {
 $this->_elementFactory = $elementFactory;
 parent::__construct($context,$data);
 }
 protected function _construct()
 {
 $this->addColumn('field1', ['label' => __('Field1')]);
 $this->addColumn('field2', ['label' => __('FIeld2')]);
 $this->_addAfter = false;
 $this->_addButtonLabel = __('Add');
 parent::_construct();
 }
}

You have display table in configuration area and after saving its value are saved inside core_config_data table.

Kishan Savaliya
7,8451 gold badge14 silver badges29 bronze badges
answered Dec 23, 2015 at 5:19
6
  • it's working fine. But when I save like <test> it is displaying &lt;test2&gt;. Any suggestion? Commented Dec 23, 2015 at 5:34
  • Hi, having doubt, If i wish to to add another group which consists same fields , frontend model, backend model which you have added in your system.xml then how Do I add another group with same system.xml file. while adding new group ,whether it will load the template properly ? Commented Feb 12, 2018 at 8:35
  • @Rakesh Jesadiya , Please have a look and answer magento.stackexchange.com/questions/212229/… Commented Feb 12, 2018 at 8:38
  • hi @rakesh Jesadiya, i have added fields using above code but unable to save and there is error on console field(qty) not defined. Commented Apr 26, 2018 at 13:01
  • How to create the rows in this admin config table programmatically ? Commented May 15, 2018 at 11:37
6

The equivalent for adminhtml/system_config_backend_serialized_array in Magento 2 is Magento\Config\Model\Config\Backend\Serialized\ArraySerialized.
You can take as example the field User-Agent Exceptions from config and try to replicate it.
The field is defined in Magento/Backend/etc/adminhtml/system.xml

answered Dec 22, 2015 at 8:32
2
  • Yes. It's exactly what I'm looking for. Thank you very much. Commented Dec 23, 2015 at 4:28
  • hi @marius, i have added fields using code $this->addColumn('value', ['label' => __('Value')]); $this->addColumn('qty', ['label' => __('Qty')]); but unable to save and there is error on console field(qty) not defined Please help Commented Apr 27, 2018 at 6:56

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.