- Update package name from shopkeeper/vendornotes to shopkeeper/module-vendor-notes to follow naming conventions - Fix invalid CSS selector issue by prefixing numeric row IDs with 'row_' in getArrayRows() - Resolves JavaScript error: "Failed to execute 'querySelectorAll' on 'Document': 'tr#0 button.action-delete' is not a valid selector" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?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
|
|
{
|
|
/**
|
|
* Initialise form fields
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function _construct()
|
|
{
|
|
parent::_construct();
|
|
$this->setTemplate('Magento_Config::system/config/form/field/array.phtml');
|
|
}
|
|
|
|
/**
|
|
* 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'
|
|
]);
|
|
|
|
$this->addColumn('note', [
|
|
'label' => __('Note'),
|
|
'class' => 'required-entry',
|
|
'style' => 'width:400px'
|
|
]);
|
|
|
|
$this->_addAfter = false;
|
|
$this->_addButtonLabel = __('Add Vendor Note');
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
// Ensure row IDs are prefixed with a non-numeric character
|
|
if (is_numeric($key)) {
|
|
$key = 'row_' . $key;
|
|
}
|
|
$result[$key] = $row;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
} |