速录CMS 2.0:如何在分类选择中使用jexl?

Sulu CMS 2.0: How to use jexl in Category Selection?

是否有一些关于如何为 category_selection 内容类型编写 jexl 的文档? current 2.0 documentation 这个话题有点单薄。

我瞎试了:

<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>

但它甚至不会抛出错误 ;)。

我尝试做的是,只允许选择某个子类别的子项。

您几乎正确地完成了,唯一的问题是可用值正是 API returns。在类别的情况下,parent 键指的是父项的 ID。而且您不会收到错误消息,因为您可以访问数字的 key 属性,唯一的问题是它会是 undefined.

所以你可以做的是:

<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>

我知道这不是很好,因为您必须将数据库 ID 放入配置中,但这是我认为目前有效的唯一方法...如果 parent.key 应该有效,我们会必须调整 API.

目前 /admin/api/categories 返回的类别 json 如下所示:

{
  "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
}