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.
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"
-
look into this magento.stackexchange.com/questions/86147/… it will help outBojjaiah– Bojjaiah2015年12月22日 08:39:24 +00:00Commented Dec 22, 2015 at 8:39
-
Thank you. But I think the answer from @Marius is what I need.thienphucvx– thienphucvx2015年12月23日 04:32:20 +00:00Commented Dec 23, 2015 at 4:32
2 Answers 2
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.
-
it's working fine. But when I save like
<test>it is displaying<test2>. Any suggestion?Bojjaiah– Bojjaiah2015年12月23日 05:34:52 +00:00Commented 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 ?Jaisa– Jaisa2018年02月12日 08:35:25 +00:00Commented Feb 12, 2018 at 8:35
-
@Rakesh Jesadiya , Please have a look and answer magento.stackexchange.com/questions/212229/…Jaisa– Jaisa2018年02月12日 08:38:06 +00:00Commented 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.faizanbeg– faizanbeg2018年04月26日 13:01:11 +00:00Commented Apr 26, 2018 at 13:01
-
How to create the rows in this admin config table programmatically ?Ashwani Shukla– Ashwani Shukla2018年05月15日 11:37:47 +00:00Commented May 15, 2018 at 11:37
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
-
Yes. It's exactly what I'm looking for. Thank you very much.thienphucvx– thienphucvx2015年12月23日 04:28:06 +00:00Commented 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 helpfaizanbeg– faizanbeg2018年04月27日 06:56:16 +00:00Commented Apr 27, 2018 at 6:56