当我使用Drupal控制台创建自定义实体时:
drupal generate:entity:content
然后默认生成菜单路径,它们工作得很好,即在结构菜单中有两个条目用于列出实体和管理自定义实体,它包括管理字段、管理表单显示和管理显示的子菜单。
现在,为了避免结构菜单混乱,我喜欢在 SystemController::systemAdminMenuBlockPage 下的路径下收集所有自定义元素 uf 一个模块/admin/structure/myCustoModuleGroup/myCustomEntityType
通过将"myCustoModuleGroup"插入实体注释和MyCustomEntityHtmlRouteProvider中的路径中,这很容易。然后我更新 mymodule.links.task.yml 的base_route
但是,管理字段等的所有子菜单都将消失。这可能是因为他们不再有正确的父级。
我想以以下菜单条目结束:
structure->CustomModule->CustomEntity1Type->Manage Fields
structure->CustomModule->CustomEntity1Type->Manage Form Display
structure->CustomModule->CustomEntity1Type->Manage Display.
structure->CustomModule->CustomEntity2Type->Manage Fields
等。
有人能够解决这个问题吗?我假设有一种方法可以在代码中更改菜单链接父级,因为它肯定是在某处声明的,但我找不到它(花了一整天的时间尝试(。
我能够在custom_entity.links.menu.yml中像这样工作:
entity.custom_entity.fields:
title: 'Manage fields'
route_name: entity.custom_entity.field_ui_fields
description: 'Manage fields'
parent: entity.custom_entity.collection
weight: 1
entity.custom_entity.form-display:
title: 'Manage form display'
route_name: entity.entity_form_display.custom_entity.default
description: 'Manage form display'
parent: entity.custom_entity.collection
weight: 2
entity.custom_entity.display:
title: 'Manage display'
route_name: entity.entity_view_display.custom_entity.default
description: 'Manage display'
parent: entity.custom_entity.collection
weight: 3