1

Now, I've got empty dropdown.

Here is my code (InstallData.php):

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
 $setup->startSetup();
 $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
 $eavSetup->addAttribute(
 \Magento\Catalog\Model\Category::ENTITY,
 'width',
 [
 'type' => 'int',
 'label' => 'Width',
 'input' => 'select',
 'source' => 'Magento\Catalog\Model\Category\Attribute\Source\Page',
 'required' => false,
 'sort_order' => 4,
 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
 'is_html_allowed_on_front' => true,
 'group' => 'General Information',
 ]
 );
 $setup->endSetup();
}

And category_form.xml:

<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <fieldset name="display_settings">
 <field name="width">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="formElement" xsi:type="string">select</item>
 <item name="label" xsi:type="string" translate="true">Width</item>
 <item name="options" xsi:type="array">
 <item name="33" xsi:type="string">33</item>
 <item name="50" xsi:type="string">50</item>
 </item>
 <item name="default" xsi:type="number">50</item>
 </item>
 </argument>
 </field>
 </fieldset>
</form>
asked Sep 12, 2017 at 13:43

1 Answer 1

2

Add following line


<item name="options" xsi:type="object">Magento\Catalog\Model\Category\Attribute\Source\Page</item>

So your xml looks like


<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <fieldset name="display_settings">
 <field name="width">
 <argument name="data" xsi:type="array">
 <item name="options" xsi:type="object">Magento\Catalog\Model\Category\Attribute\Source\Page</item>
 <item name="config" xsi:type="array">
 <item name="formElement" xsi:type="string">select</item>
 <item name="label" xsi:type="string" translate="true">Width</item>
 <item name="options" xsi:type="array">
 <item name="33" xsi:type="string">33</item>
 <item name="50" xsi:type="string">50</item>
 </item>
 <item name="default" xsi:type="number">50</item>
 </item>
 </argument>
 </field>
 </fieldset>
</form>

Clear cache.

answered Sep 12, 2017 at 14:24
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.