Magento – Magento2 : multi select box is not showing option with custom source

magento2multiselect

Working on custom extension, I have implemented multi select option using custom source. It don't show the option in multi select box. Anybody knows the reason?
Check screenshot,

$eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'extension_source_user',
            [
                'type' => 'varchar',
                'label' => 'Used Title',
    'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
                'input' => 'multiselect',
    'source' => 'company\extension\Model\Source\Custom\User',
                'required' => false,
                'sort_order' => 7,
                'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
    'apply_to' => 'simple,configurable,virtual',
                'group' => 'company',
    'searchable'        => false,
    'filterable'        => false
            ]
        );

enter image description here

Best Answer

It the issue of your source model "'source' => 'company\extension\Model\Source\Custom\User'"

You need to return option array in the form of key, value pair like :

public function getOptionArray()
{
    $_options = array();
    foreach ($this->getAllOptions() as $option) {
        $_options[$option["value"]] = $option["label"];
    }
    return $_options;
}
Related Topic