I was reading through https://api.drupal.org/api/drupal/core!includes!menu.inc/group/menu/8 and saw mention of base_route, but not parent_id. 8.0.x however uses a mix of the two and I couldn't quite grasp why.
The change notice at https://www.drupal.org/node/2044515 has actually quite excellent documentation (which we need to move into https://api.drupal.org/api/drupal/core!includes!menu.inc/group/menu/8 somewhere). It mentions that base_route is for top-level local tasks, and parent_id is for second-level local tasks. But that's a) completely non-obvious that that's what the difference is, and b) seems like a WTF to have to change the key that means "the parent route" depending on where you are declaring your tabs.
So my preference would be to use base_route (or parent_id, or parent_route, I don't really care) consistently throughout and have the menu system figure out what you meant.
Comments
Comment #1
webchickActually, *links.menu.yml calls this just "parent" so suggesting the same here.
Comment #2
dawehnerIn general you have to understand that the different patterns, menu links, local actions, contextual links and local tasks
do have totally different usecases. The only common thing is that they provide a link with route names + parameters aka. a URL (which was provided by hook_menu()). Making it explicit that they work different helps, see http://legacy.python.org/dev/peps/pep-0020/
Peter described that point in his own words:
When we started with local tasks in #2004334: Separate Tabs (MENU_LOCAL_TASK) from hook_menu() we wanted to decouple the hierarchy structure of local tasks from route names. So an example would have looked like the following. As you see, the route name did actually not mattered at all
People complained, so this got changed in #2107531: Improve DX of local task YAML definitions to contain less keys. Sadly that changed removed explicitness, but removed the amount of typing you
need.
Maybe you have not realized, but there is a difference between "parent" and base_route (or tab_root_id as before). The parent describes
a hierarchical relationship, the tab_root_id/base_route describe a sibling relationship. I think not making this explicit will
especially be worse in terms of understanding. Why should the parent key work different, depending on the context.
Comment #3
webchickI guess that level of understanding of the underpinnings of the menu system is not something I would expect to have to know in order to simply add some tabs to my module's admin interface (this is a very common task). Even forgetting everything I already know about D7 and below, a tabset like this certainly "feels" like a hierarchy, even if under the hood it's represented as a series of siblings:
We already communicate via the different file names that links.menu.yml and links.tasks.yml are different and work differently. So I don't understand the resistance to re-using property names so there are fewer concepts for new developers to learn?
Basically, in my ideal world, this is what that would be:
But if that's seen as too much of a departure, I'd also settle for "pick one" between base_route / parent_id, rather than needing to use a completely different property depending on the "depth" of your tasks.
Comment #4
dawehnerPlease don't consider this as a attack to you, its just the fact that we had all this discussion earlier as well.
You wanna say that people should not actually understand what they are doing (creating siblings + hierarchies) but instead turn off their
brain and just write something together which seems to work, without any concrete clue what is going on, especially in the future,
when people actually have to reread their code/YML files? You proposal makes it incredible hard to change in the future, as you need much more context.
Previously you could read a single definition and know where it appears (root level, child level). With your proposal you have to move along the trail in order to figure that out. We need to take more metrics into account that the amount of keystrokes.
You will not convince me to use a hierarchic description for something non-hierarchical but well I won't fight here,
but at least let me quote someone from the community when I talked about your idea: "This makes no sense".
Talking about parent vs. parent_id, we went with the second one, to communicate clearly that these are plugins IDs, not route names or whatever.
Comment #5
webchickGuess that settles that then. Sigh.