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

webchick’s picture

Title: *.links.task.yml: Either document parent_id or drop it in favour of base_route everywhere » *.links.task.yml: Drop parent_id/base_route in favour of "parent" like menu links

Actually, *links.menu.yml calls this just "parent" so suggesting the same here.

dawehner’s picture

In 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:

good DX is NOT ONLY about what you have type the 1st time, it should also be about reducing the WTF factor when you come back to it 6 months later or are looking at it as a novice.

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

views_ui_list_tab:
  route_name: ...
  title: ...
  tab_root_id: views_ui_list_tab
views_ui_settings_tab:
  route_name: ...
  title: ...
  tab_root_id: views_ui_list_tab
views_ui_settings_advanced_tab:
  route_name: ...
  title: ...
  tab_root_id: views_ui_list_tab
  tab_parent_id: views_ui_settings_tab
views_ui_settings_basic_tab:
  route_name: ...
  title: ...
  tab_root_id: views_ui_list_tab
  tab_parent_id: views_ui_settings_tab

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.

views_ui.settings_tab:
  route_name: views_ui.settings_basic
  title: Settings
  base_route: views_ui.list

views_ui.settings_basic_tab:
  route_name: views_ui.settings_basic
  title: Basic
  parent_id: views_ui.settings_tab

views_ui.settings_advanced_tab:
  route_name: views_ui.settings_advanced
  title: Advanced
  parent_id: views_ui.settings_tab
  weight: 10

views_ui.list_tab:
  route_name: views_ui.list
  title: List
  base_route: views_ui.list

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.

webchick’s picture

I 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:

Tabs and sub-tabs

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:

views_ui.list_tab:
  route_name: views_ui.list
  title: List
views_ui.settings_tab:
  route_name: views_ui.settings_basic
  title: Settings
  parent: views_ui.list_tab
views_ui.settings_basic_tab:
  route_name: views_ui.settings_basic
  title: Basic
  parent: views_ui.settings_tab
views_ui.settings_advanced_tab:
  route_name: views_ui.settings_advanced
  title: Advanced
  parent: views_ui.settings_tab
  weight: 10

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.

dawehner’s picture

Please don't consider this as a attack to you, its just the fact that we had all this discussion earlier as well.

I 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).

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.

webchick’s picture

Status: Active » Closed (won't fix)

Guess that settles that then. Sigh.