I created a custom category attribute "category_special" and placed it in the category form via ui_component. There I can select categories like in the Magento default product form. The attribute is visible in the category form. After saving the category the attribute content is still empty. Do I have to choose a specific backend model for the attribute or something like this?
Setup\InstallData.php
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'category_special',
[
'type' => 'text',
'input' => 'select',
'label' => 'Category Special',
'visible' => true,
'required' => false,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'source' => '',
'default' => null,
]
);
view/adminhtml/ui_component/category_form.xml
<field name="category_special">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Catalog\Ui\Component\Product\Form\Categories\Options</item>
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Category Special</item>
<item name="componentType" xsi:type="string">field</item>
<item name="formElement" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Catalog/js/components/new-category</item>
<item name="elementTmpl" xsi:type="string">ui/grid/filters/elements/ui-select</item>
<item name="dataScope" xsi:type="string">category_special</item>
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="showCheckbox" xsi:type="boolean">true</item>
<item name="disableLabel" xsi:type="boolean">true</item>
<item name="multiple" xsi:type="boolean">true</item>
<item name="levelsVisibility" xsi:type="number">1</item>
<item name="sortOrder" xsi:type="number">20</item>
<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="listens" xsi:type="array">
<item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
</item>
</item>
</argument>
</field>