Hello everybody! :) I'm getting straight to the point.

So, my goal is to extend menu links so that they can not only have other (manually created) menu links as children but also (upon frontend rendering) have an additional list of automatically created child links. As an example, a menu link could have an additional reference field to a taxonomy term and then all taxonomy terms beneath that term would get rendered as menu link children in the frontend, possibly even nested.

Sounds easy enough. I could create a new field for menu links - an entity reference to taxonomy terms. But this is just one example. I want to be flexible with the generation of such a the list (or even tree). Another example could be the backend user selecting a node type and the automatically created list of child links would be links to all nodes of that type. Or the user can reference another menu which will be inserted as sub menu, so to say. Each different way to produce such a list (or tree) of child links would have its own configuration with its own list of fields. It could even be desirable to add a mixture of different lists, created in different ways.

Currently I don't care all too much about how this should be rendered in the frontend. My first step is to visualise how to implement such a data structure. So I went digging for a bit, but quickly realised that even if I found a way to do this, I would not be sure if this is the best (or even a good) way to do it. That's why I ended up writing this post.

Initially I thought I could just create a widget. But if I'm not mistaken, a widget only controls how the UI behaves, and does not automatically provide a data structure that can be saved as an entity field, especially since the fields would have to be dynamic.

I read a bit about plugins and they might help me at some point, but they seem to be groups of services with which I can apply different algorithms all achieving the same goal through different means. Which does sound good for the frontend part, but I don't think they can help me with the data structure that I have to declare.

My last thought on this is to create a new entity type "MenuLinkContentList" and create a bundle for each way of building child link lists. For example the bundles could be called "TaxonomyTermLinkTree", "NodeTypeLinkList", "SubMenuLinkTree" and so on. Each bundle could have its own set of fields. So the fields being dynamic would not be a problem anymore.

The original entity MenuLinkContent could then get a new field which is holding references (plural) to entities of this new type. During the rendering I would hook somewhere or subscribe to an event, read the new field for each menu link and update the menu link tree with the additional items.

On top of that, I would like to have these entity references being editable inline within the edit form of a MenuLinkContent, because each MenuLinkContentList would be bound to exactly one MenuLinkContent entity. I have heard of entities being created, edited and deleted in an embedded form within the edit form of another (surrounding) entity. For example URL Path Aliases can do this in the Node edit form. If I'm not mistaken, this is a specific kind of widget. But I don't think I've seen this for a 1:n relation, meaning that one MenuLinkContent can have multiple MenuLinkContentLists inline. Is this possible? It almost feels like I am trying to implement paragraphs for menu links, but in a very specific, narrowed way (and without nesting). I'm hoping that it would not be that complicated.

Overall, I feel like I have found a strategy - a new entity type (MenuLinkContentList) which is referenced by the one that I want to extend (MenuLinkContent) - but it was a lot of going back and forth to get there. So at this point I am wondering, if I am on the right track at all. Maybe there is a much easier way to achieve this goal. And even if this is a good strategy, I am not completely sure how to do the actual implementation. Hints and pointers to documentation and tutorials that might help me are very welcome.

Any feedback and input is appreciated. Thank you!