I try to create a category attribute in a Magento 2 install script (or how do we call these now?)
In Magento 1, I could specify anything as group
and the group would be created. In Magento 2 this seems not to be the case anymore, so I created the group explicitly first:
$eavSetup->addAttributeGroup(
Category::ENTITY,
$eavSetup->getDefaultAttributeSetId(Category::ENTITY),
'My group name',
99
);
$eavSetup->addAttribute(
Category::ENTITY,
'my_attribute_code',
[
'type' => 'int',
'input' => 'select',
'source' => Boolean::class,
'label' => 'My attribute',
'group' => 'My group name',
'visible' => 1,
]
);
The attribute and attribute group is created in the database (eav_attribute
and eav_attribute_group
, as well as the relation in eav_entity_attribute
) but I still do not see the attribute in the backend. What am I missing?
Best Answer
Thanks to @SohelRana I found out that you now have to write a bunch of additional XML to make anything appear in the category form. Since the answer linked above does not explain how to add a new group, I'll share my result (for one boolean attribute) here:
view/adminhtml/ui_component/category_form.xml
The
argument
element withinfieldset
is necessary to define the properties of the new group. Anything related to attribute group and the admin forms in the database, i.e. from the install script seems to be ignored.