2

in magento 2.1 there is user friendly box generated for "Categories" field. enter image description here

I am trying to apply this box for custom field in category form, but without success so far.

I tried to create similar, like in https://github.com/magento/magento2/blob/2.1.0-rc3/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php, but without success. It makes it harder, that form implementation is different between product and category.

XML file for category form https://github.com/magento/magento2/blob/2.1.0-rc3/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml

XML file for product form https://github.com/magento/magento2/blob/2.1.0-rc3/app/code/Magento/Catalog/view/adminhtml/ui_component/product_form.xml

Someone knows, how to achieve this ?

0

I have the beginning of the anwser. When you create your form, you have to set up a new field type like this:

   $fieldset->addType(
    'categories',
    '\Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category'
   );

Then you can use it :

        $fieldset->addField(
        'categories_id',
        'categories',
        [
            'name' => 'categories_id',
            'label' => __('Categories'),
            'title' => __('Categories')

        ]
    );

And then you will have your categories field! But last issue the rendering is broken because Magento use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories to enhance it. I don't know how to use this modifier to apply it on the custom categories field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.