sulu 2.2:有没有办法让 category_selection 内容类型中的类别按名称自动排序?

sulu 2.2: Ist there a way that categories in the category_selection content type are sorted automatically by name?

有没有办法让 category_selection 内容类型的显示类别按名称而不是 ID 排序?它们是通过 ajax 从 api 加载的,例如 http://localhost:8000/admin/api/categories?locale=de&selectedIds=7&fields=name,id&flat=true

如果有像类别概述中那样添加排序的稳定方法,那将是一个很好的补充。

无法按字母顺序对它们进行排序。

但是您可以覆盖 CategoryController 并在 getListRepresentation 方法中的 initializeListBuilder 调用之后添加 $listBuilder->sort($fieldDescriptors['name']);

编辑: 我刚刚发现,无论如何我们都需要一个默认的排序顺序,否则两个相同请求的结果顺序可能不同。我创建了一个包含更改的拉取请求 https://github.com/sulu/sulu/pull/6136

在此修复发布之前,您可以覆盖您的 CategoryController 并手动添加排序。

Edit2:如何覆盖控制器:

首先,您必须创建自己的控制器并从 CategoryController 扩展并覆盖特定方法,例如:

class CustomCategoryController extends SuluCategoryController
{
protected function getListRepresentation(
    Request $request,
    $locale,
    $parentId = null,
    $expandedIds = [],
    $expandSelf = false,
    $includeRoot = false
) {
    $listBuilder = $this->initializeListBuilder($locale);
     <add default sort here>
     <copy the rest of the original function here>
    }
}

第二步是将此服务添加到services.yaml文件中,并添加一个别名来覆盖原来的CategoryController:

App\Controller\Admin\CustomCategoryController:
    alias: sulu_category.category_controller