1

I've got a custom category attribute on backend which is currently available for all categories.

I want this attribute to be available for main categories only. In order to achieve this I've added a data provider to my module which extends \Magento\Catalog\Model\Category\DataProvider and (following this link: Disabling a UI component field upon condition in Magento 2) I've added this line to my category_form.xml:

<item name="disabled" xsi:type="string">${ $.provider }:data.do_we_hide_it</item>

But now I'm stuck: I don't understand how to inject my new value (data.do_we_hide_it): in the previous link it's said to use the getData method but I cannot understand how to do it.

Can you help me?

My data provider now has nothing more than the getData method:

class DataProvider extends \Magento\Catalog\Model\Category\DataProvider {
 public function getData() {
  $data = parent::getData();
  return $data;
 }
}

If I leave the method as it is (it simply extends the parent method), I get the categories with my field disabled for all the categories. If I add the lines as explained in the link, I get a blank page.

Can someone help me?

1
  • I figured it out: I only added the item disabled line but instead that line needs to be enclosed in another item node. So basically, the line inside category_form.xml is : <item name="imports" xsi:type="array"><item name="disabled" xsi:type="string">${ $.provider }:data.do_we_hide_it</item></item>. – Lounik Nov 23 '17 at 10:57

Your Answer

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

Browse other questions tagged or ask your own question.