2025-10-07 18:57:28 -04:00
|
|
|
<?php
|
|
|
|
|
namespace Shopkeeper\VendorNotes\Block\Adminhtml\Form\Field;
|
|
|
|
|
|
|
|
|
|
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
|
|
|
|
|
use Magento\Framework\DataObject;
|
|
|
|
|
|
|
|
|
|
class VendorMapping extends AbstractFieldArray
|
|
|
|
|
{
|
2025-11-06 14:23:40 -05:00
|
|
|
/**
|
|
|
|
|
* Initialise form fields
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function _construct()
|
|
|
|
|
{
|
|
|
|
|
parent::_construct();
|
|
|
|
|
$this->setTemplate('Magento_Config::system/config/form/field/array.phtml');
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 18:57:28 -04:00
|
|
|
/**
|
|
|
|
|
* Prepare rendering the new field by adding all the needed columns
|
|
|
|
|
*/
|
|
|
|
|
protected function _prepareToRender()
|
|
|
|
|
{
|
|
|
|
|
$this->addColumn('vendor_name', [
|
|
|
|
|
'label' => __('Vendor Name'),
|
|
|
|
|
'class' => 'required-entry',
|
|
|
|
|
'style' => 'width:200px'
|
|
|
|
|
]);
|
2025-11-06 14:23:40 -05:00
|
|
|
|
2025-10-07 18:57:28 -04:00
|
|
|
$this->addColumn('note', [
|
|
|
|
|
'label' => __('Note'),
|
|
|
|
|
'class' => 'required-entry',
|
|
|
|
|
'style' => 'width:400px'
|
|
|
|
|
]);
|
2025-11-06 14:23:40 -05:00
|
|
|
|
2025-10-07 18:57:28 -04:00
|
|
|
$this->_addAfter = false;
|
|
|
|
|
$this->_addButtonLabel = __('Add Vendor Note');
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-06 14:23:40 -05:00
|
|
|
/**
|
|
|
|
|
* Obtain existing data from form element
|
|
|
|
|
*
|
|
|
|
|
* Each row will be instance of Varien_Object
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getArrayRows()
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
|
|
|
|
/** @var DataObject $row */
|
|
|
|
|
foreach (parent::getArrayRows() as $key => $row) {
|
2025-11-10 12:58:58 -05:00
|
|
|
// Ensure row IDs are prefixed with underscore to make valid CSS selectors
|
|
|
|
|
// CSS IDs cannot start with a number
|
2025-11-06 14:23:40 -05:00
|
|
|
if (is_numeric($key)) {
|
2025-11-10 12:58:58 -05:00
|
|
|
$key = '_' . $key;
|
2025-11-06 14:23:40 -05:00
|
|
|
}
|
2025-11-10 12:58:58 -05:00
|
|
|
// Also set the _id property in the row data for proper rendering
|
|
|
|
|
$row->setData('_id', $key);
|
2025-11-06 14:23:40 -05:00
|
|
|
$result[$key] = $row;
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 18:57:28 -04:00
|
|
|
/**
|
|
|
|
|
* Prepare existing row data object
|
|
|
|
|
*
|
|
|
|
|
* @param DataObject $row
|
|
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException
|
|
|
|
|
*/
|
|
|
|
|
protected function _prepareArrayRow(DataObject $row): void
|
|
|
|
|
{
|
|
|
|
|
$options = [];
|
|
|
|
|
$row->setData('option_extra_attrs', $options);
|
|
|
|
|
}
|
|
|
|
|
}
|