I've something like this:
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'test_att',
[
'type' => 'varchar',
'input' => 'select',
'input' => 'text',
'required' => false,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => 1,
'unique' => false,
'apply_to' => 'simple,configurable',
'group' => 'test',
]
);
I want to use an object to get the options from a dynamic method instead of a fixed array.
According to EavSetup addAttribute method it's not possible because the option parameter expects an array
if (isset($attr['option']) && is_array($attr['option'])) {
$option = $attr['option'];
$option['attribute_id'] = $this->getAttributeId($entityTypeId, $code);
$this->addAttributeOption($option);
}
So I used product_form.xml
<fieldset name="test">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">test</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<field name="test_att">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Company\Module\Model\Source\Object</item>
<item name="config" xsi:type="array">
<item name="required" xsi:type="boolean">false</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">false</item>
</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">select</item>
</item>
</argument>
</field>
</fieldset>
It works BUT two dropdowns are shown, one using the options from the object, one not (empty select). Also the customized dropdown has no scope selector or scope label.
Same solution works for custom category attributes (even if without scope)
How to do it ??? Probably I misunderstood something