My config file after save config data
After save data It also show error in console as there is no any field
after save data it does not give me unserialaize data my php file to render data in table is
<?php
namespace Vendor\Module\Block\Adminhtml;
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Vendor\Module\Block\Adminhtml\PaymentMethod;
use Vendor\Module\Block\Adminhtml\UnitMethod;
class Payment extends AbstractFieldArray
{
private $pymentRenderer;
private $unitRenderer;
protected function _prepareToRender()
{
$this->addColumn('paymentmethod', [
'label' => __('Payment Method'),
'renderer' => $this->getPaymentRenderer()
]);
$this->addColumn('duration', ['label' => __('Duration'), 'class' => 'required-entry']);
$this->addColumn('unit', [
'label' => __('Units'),
'renderer' => $this->getUnitRenderer()
]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
protected function _prepareArrayRow(DataObject $row): void
{
$options = [];
$pm = $row->getPaymentMethod();
$unit = $row->getUnitMethod();
if ($pm !== null) {
$options['paymentmethod_' . $this->getPaymentRenderer()->calcOptionHash($pm)] = 'selected="selected"';
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info(print_r($options,true));
$row->setData('paymentmethod', $options);
}
$options = [];
if ($unit !== null) {
$options['unit_' . $this->getUnitRenderer()->calcOptionHash($unit)] = 'selected="selected"';
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info(print_r($options,true));
$row->setData('unit', $options);
}
}
private function getPaymentRenderer()
{
if (!$this->pymentRenderer) {
$this->pymentRenderer = $this->getLayout()->createBlock(
paymentmethod::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->pymentRenderer;
}
private function getUnitRenderer()
{
if (!$this->unitRenderer) {
$this->unitRenderer = $this->getLayout()->createBlock(
unitmethod::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->unitRenderer;
}
}
-
Did you find solution? I am facing same problem.Rushabh Dave– Rushabh Dave2020年07月04日 18:20:52 +00:00Commented Jul 4, 2020 at 18:20
-
any solution on this issue? @ArjunManisha Vasani– Manisha Vasani2023年05月12日 14:06:27 +00:00Commented May 12, 2023 at 14:06
1 Answer 1
With reference to you console output, you need to modify your _prepareArrayRow function like this:
protected function _prepareArrayRow(DataObject $row): void
{
$options = [];
$pm = $row->getPaymentMethod();
$unit = $row->getUnitMethod();
if ($pm !== null) {
$options['paymentmethod_' . $this->getPaymentRenderer()->calcOptionHash($pm)] = 'selected="selected"';
}
if ($unit !== null) {
$options['unit_' . $this->getUnitRenderer()->calcOptionHash($unit)] = 'selected="selected"';
}
$row->setData('option_extra_attrs', $options);
}
Note: If you skip the label for dynamic field in system.xml, it won't save.
This is working on Magento 2.3.5 enterprise edition
Explore related questions
See similar questions with these tags.