1
votes

When I create a custom entity using Drupal console:

drupal generate:entity:content

then Menu paths are generated by default and they work very nicely, i.e. in the Structure Menu there are two entries for Listing entities and for Managing the Custom entity, and it includes sub-menus for Manage Fields, Manage Form Display, and Mangage Display.

Now, to avoid cluttering the structure menu, I like to gather all custom enitites uf a module under a SystemController::systemAdminMenuBlockPage under a path /admin/structure/myCustoModuleGroup/myCustomEntityType

This is easy by inserting 'myCustoModuleGroup' into the paths in the entity annotations and in MyCustomEntityHtmlRouteProvider. Then I update the base_route of the mymodule.links.task.yml

However, then all the submenus for Manage Fields, etc., disappear. This is probably because they no longer have the correct parent.

I would like to end up with Menu entries for:

structure->CustomModule->CustomEntity1Type->Manage Fields
structure->CustomModule->CustomEntity1Type->Manage Form Display
structure->CustomModule->CustomEntity1Type->Manage Display.

structure->CustomModule->CustomEntity2Type->Manage Fields

etc.

Has anybody been able to solve this? I assume there is a way to change the menu link parent in code, since it was certainly declared somewhere, but I cannot find it (spent a whole day trying).

1

1 Answers

2
votes

I was able to get this working in custom_entity.links.menu.yml like this:

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