【问题标题】:Drupal 8 Custom entity Menu PathsDrupal 8 自定义实体菜单路径
【发布时间】:2018-09-30 12:10:32
【问题描述】:

当我使用 Drupal 控制台创建自定义实体时:

drupal generate:entity:content

然后菜单路径是默认生成的,它们工作得很好,即在结构菜单中有两个条目用于列表实体和管理自定义实体,它包括管理字段、管理表单显示和管理显示。

现在,为了避免结构菜单混乱,我喜欢在路径下的 SystemController::systemAdminMenuBlockPage 下收集模块的所有自定义实体 /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

等等

有人能解决这个问题吗?我认为有一种方法可以在代码中更改菜单链接父级,因为它肯定是在某处声明的,但我找不到它(花了一整天的时间尝试)。

【问题讨论】:

    标签: drupal menu parent drupal-8 entities


    【解决方案1】:

    我能够像这样在 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
    

    【讨论】:

    • 做到了。非常感谢!
    • 捆绑实体做这件事有什么好运气吗?我认为这需要在代码中完成,而不是在 .yml 配置中。然而,对于非捆绑实体,您的解决方案就像一个魅力。
    • 抱歉,目前在这个项目中不使用捆绑包。但在我看来,确实有可能改变代码以使其正常工作。您可以接受我的回答作为您遇到的问题的解决方案;)
    猜你喜欢
    • 2016-10-21
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    相关资源
    最近更新 更多