0

Is there somewhere a bit of documentation how to write jexl for the category_selection Content Type? The current 2.0 documentation is a bit thin in this topic.

I tried blindly:

<property name="authors" type="category_selection">
   <meta>
      <title lang="de">Autor</title>
      <title lang="en">Author</title>
   </meta>

   <params>
      <param name="item_disabled_condition" value="parent.key == 'authors'"/>
   </params>
</property>

But it does not even throw an error ;).

What I try to do is, to allow only selection of children of a certain sub category.

Andreas
  • 1,691
  • 1
  • 15
  • 34

1 Answers1

1

You have done it almost correctly, the only problem is that the available values are exactly what the API returns. And in the case of categories, the parent key refers to the ID of the parent. And you don't get an error because you can access the key attribute on a number, the only problem is that it will be undefined.

So what you can do is the following:

<property name="authors" type="category_selection">
   <meta>
      <title lang="de">Autor</title>
      <title lang="en">Author</title>
   </meta>

   <params>
      <param name="item_disabled_condition" value="parent == 1"/>
   </params>
</property>

I know that this is not really nice, because you have to put a database ID into a configuration, but that's the only way I see that currently working... If parent.key should work, we would have to adjust the API.

Currently a category json returned by /admin/api/categories looks like this:

{
  "name": "Cat Name", // name in the selected language
  "id": 6,
  "depth": 2, // depth in the tree
  "parent": 2, // id of the parent
  "locale": "de",
  "defaultLocale": "de",
  "lft": 5,
  "rgt": 6,
  "hasChildren": false
}
Andreas
  • 1,691
  • 1
  • 15
  • 34
Daniel Rotter
  • 1,998
  • 2
  • 16
  • 33
  • Thx a lot for this! I'll check it out. Is there a way to see or debug what values are available? Also an issue with database id's is, that they will be different between development, staging and live systems. I will try a bit and see if I can get it to work with multiple database ids for the multipe systems. – Andreas Apr 28 '20 at 13:36
  • But yes, access to the key would make it imho much more useful :) – Andreas Apr 28 '20 at 13:37
  • Hm, the way I check which values is available, is that I have a look at the request loading the items in the network tab of the browser's dev tools... Not very elegant, I know. But I could e.g. also imagine to log every check done by the `item_disabled_condition` to the console. I guess that would help, although you would still have to know where to look... – Daniel Rotter Apr 29 '20 at 14:10
  • Ok, so one year later I can confirm it actually works. But it is a pitty, that there is no way to actualy savely accross multiple instalations exclude or filter whole category trees. – Andreas Jun 29 '21 at 20:50