I'm facing to a very ridiculous trouble, I added a custom product attribute with source model, backend model as a select box. Everything works fine (my custom attribute will get the values from a custom table) except the input_renderer
part.
Here is what I tried, (running on default mode)
Setup\MySetup.php
public function getDefaultEntities()
{
return [
'catalog_product' => [
'entity_model' => 'Magento\Catalog\Model\ResourceModel\Product',
'attribute_model' => 'Magento\Catalog\Model\ResourceModel\Eav\Attribute',
'table' => 'catalog_product_entity',
'additional_attribute_table' => 'catalog_eav_attribute',
'entity_attribute_collection' => 'Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection',
'attributes' => [
'custom_ids' => [
'type' => 'static',
'input' => 'select',
'label' => 'Custom Attribute',
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
'backend' => 'Vendor\Module\Model\Product\Attribute\Backend\CustomAttr',
'source' => 'Vendor\Module\Model\Product\Attribute\Source\CustomAttr',
'input_renderer' => 'Vendor\Module\Block\Adminhtml\Product\Helper\Form\CustomAttr',
'required' => false,
'sort_order' => 9,
'visible' => true,
'group' => 'General',
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
],
];
}
Block\Adminhtml\Product\Helper\Form\CustomAttr.php
class CustomAttr extends \Magento\Framework\Data\Form\Element\Select
{
public function getAfterElementHtml()
{
if (!$this->isAllowed()) {
return '';
}
$htmlId = $this->getHtmlId();
$suggestPlaceholder = __('start typing to search custom attribute');
$selectorOptions = $this->jsonEncoder->encode($this->getSelectorOptions());
$backendUrl = $this->backendData->getUrl('vendor_module/customattr_index/index/suggestCustomAttr');
$return
= <<<HTML
/** Some HTML and JavaScript here **/
HTML;
return $return;
}
}
I tried to die()
inside getAfterElementHtml()
method, but nothing happens. I even go to the database and change the value of column frontend_input_renderer
in table catalog_eav_attribute
to something doesn't exists.
But there is NO ERROR at all !!! Magento 2 just simply to denied to call my input renderer :)
Anyone here have any suggestions or a best pratices for this?
Thank you.