I am creating multi-column config, the problem is it's only setting the value of the first select field, the second field is not being selected following is my code :
<?php
namespace Aayanshtech\Adminsection\Block\System\Config\Form\Field;
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
/**
* Class Active
*
* @package Aayanshtech\Adminsection\Block\System\Config\Form\Field
*/
class Fields extends AbstractFieldArray {
/**
* @var bool
*/
protected $_addAfter = TRUE;
/**
* @var
*/
protected $_addButtonLabel;
protected $_activation;
protected $_sec_one_action;
/**
* Construct
*/
protected function _construct() {
parent::_construct();
$this->_addButtonLabel = __('Add Option');
}
/**
* Get activation options.
*
* @return \Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
protected function _getActivationRenderer()
{
if (!$this->_activation) {
$this->_activation = $this->getLayout()->createBlock(
'\Aayanshtech\Adminsection\Block\Adminhtml\Form\Field\Activation',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_activation;
}
protected function _getActivationRenderer2()
{
if (!$this->_sec_one_action) {
$this->_sec_one_action = $this->getLayout()->createBlock(
'\Aayanshtech\Adminsection\Block\Adminhtml\Form\Field\Seconeaction',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_sec_one_action;
}
/**
* Prepare to render the columns
*/
protected function _prepareToRender() {
$this->addColumn('field_1', ['label' => __('Distance')]);
$this->addColumn('field_2', ['label' => __('Code')]);
$this->addColumn('field_3', ['label' => __('Selection order')]);
$this->addColumn('field_4', ['label' => __('Price')]);
$this->addColumn(
'field_5',
[
'label' => __('Type of price'),
'renderer' => $this->_getActivationRenderer()
]
);
$this->addColumn(
'field_6',
[
'label' => __('Action'),
'renderer' => $this->_getActivationRenderer2()
]
);
$this->_addAfter = FALSE;
$this->_addButtonLabel = __('Add Option');
}
/**
* Prepare existing row data object.
*
* @param \Magento\Framework\DataObject $row
* @return void
*/
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$options = [];
if($row->getData('field_5')){
$customAttribute = $row->getData('field_5');
$key = 'option_' . $this->_getActivationRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
if($row->getData('field_6')){
$customAttribute = $row->getData('field_6');
$key = 'option_' . $this->_getActivationRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
}
}
I got stuck _prepareArrayRow
in this function what i want to achieve please see the screen shot.
Unable to set the value of action.