Problem/Motivation
The way that the various *links.yml files are named make it hard to easily tell what a module implements, and require module developers to know special names for each subsystem. Conceptually, these are all "links."
Proposed resolution
Rename the files to:
*.links.action
*.links.contextual
*.links.task
This makes the naming more consistent and as an added bonus makes the files appear grouped together in a directory listing.
*.links.menu
is slated to be renamed also but it will be handled in #2303605: Rename *.menu_links.yml to *.links.menu.yml files to improve DX.
Remaining tasks
Do that.
User interface changes
N/A
API changes
File names change.
Original report by @webchick
Gábor created and tweeted around this diagram:
It's lovely that we now have this documented. But holy complicated, Batman. :\ That's up to 5 different files I need to open and read in order to figure out what a module is doing. In the past I only had to look at hook_menu() and it was all there.
I totally get the benefits of splitting routing from links. I don't understand what we gain though by being this granular the types of links themselves. I think to most people it's just "links."
Proposal would be just keep:
*.menu_links.yml
And then indent the YAML definitions by an appropriate key, for example, book.menu_links.yml would be:
links:
book.admin:
title: Books
description: 'Manage your site''s book outlines.'
parent: system.admin_structure
route_name: book.admin
book.render:
title: Books
route_name: book.render
hidden: 1
local_tasks:
book.admin:
route_name: book.admin
title: 'List'
base_route: book.admin
book.settings:
route_name: book.settings
title: 'Settings'
base_route: book.admin
weight: 100
book.outline:
route_name: book.outline
base_route: node.view
title: Outline
weight: 2
What say you?
Comment | File | Size | Author |
---|---|---|---|
#25 | 2291137-25.patch | 23.91 KB | cilefen |
#25 | interdiff-23-25.txt | 1.51 KB | cilefen |
#23 | 2291137-23.patch | 33.12 KB | cilefen |
#23 | interdiff-21-23.txt | 3.65 KB | cilefen |
#21 | 2291137-21.patch | 29.23 KB | cilefen |
Comments
Comment #1
chx CreditAttribution: chx commentedComment #2
xjmI don't think that having one file versus four files is really much of a gain. Either it's long and hard to read, or you open four things. To me it makes sense to have them separated conceptually.
Comment #3
alexpottWell I guess this might depend on how many menu links, local tasks, local actions, or contextual links a module is providing. If you're providing one of each then four files might feel like overkill. But on the other hand these "links" are not the same thing and they have different data structures. Also the lack of a file makes it easy to discover when a module does not provide something.
Comment #4
effulgentsia CreditAttribution: effulgentsia commentedJust looking through core modules, looks to me like a lot provide 2 or 3.
They're both similar and different. They're all links. But they have different UX purposes and therefore get rendered in different places with different hierarchy organization.
Their data structures are both similar and different. They all share the same semantics of
title
,description
,route_name
,weight
, andclass
. But related to hierarchy, they differ with respect toparent
,parent_id
(though that's silly, it should be renamed to parent),base_route
,group
, andappears_on
.Therefore, in order to communicate/represent the similarities and differences, what about keeping them as separate files, but renaming them to:
?
Comment #5
tim.plunkettI'm hugely -1 on combining these.
However, I'm not averse to renaming them. I never liked "local tasks" and "local actions" anyway, since they're all just links.
Another options is this:
vim *.links.yml
Comment #6
tstoecklerI'm not against combining them, but between #4 and #5 I'm very much for #4.
vi *.links.yml
is nice, but so isvi mymodule.links.*
. And #4 has the benefit of neatly showing the files next to each other in the the file browser.Comment #7
Gábor HojtsyThe 'subtle' differences are even more spelled out when you want to create dynamic items of hook_menu() successors. Opened this issue to summarize the differences and similarities: #2291773: Creating dynamic hook_menu() successor items use different APIs maybe we want to do something about this, maybe not :)
Comment #8
dawehnerHaving them in separate files certainly helps people to remember that there are differences. Otherwise they really easy might just copy and paste other bits and wonder why they don't work.
I also prefer this variant but it would be great to keep it either singular or plural so:
On top of that having them in one file would make scanning of them a bit worse on the performance side, because as the
subsystems are decoupled all of them would have to read the merged file anyway. Not sure whether this though actually
matters given that it is cached but yeah a full router + menu rebuild is always potentially problematic.
Comment #9
catchWe discussed one file before, I have no idea which issue it was, from what I remember the pros and cons were similar (single file for overview vs. making the separation between systems clear and reducing parsing overhead). Another thing to consider is that (at least) contextual module is optional, so if we have information in one file we're having to parse YAML that will never be used on some sites. There's also the ability to completely ignore the other types altogether if you have a module that just adds a single settings admin page or similar.
So, I'd also like to keep single files, but I like dawehner's second variant in #8.
Comment #10
webchick#8 would definitely be a big improvement over the status quo. #3, #4, and #9 lay out a sensible reasons why we probably don't want to do what I said. Changing the title and updating the issue summary accordingly.
Comment #11
cilefen CreditAttribution: cilefen commentedThis is not clear to me: Is the intent that these would actually be named with the YAML file extension?:
Comment #12
cilefen CreditAttribution: cilefen commentedI am trying local_tasks here. This will certainly fail the bots.
Comment #13
cilefen CreditAttribution: cilefen commentedComment #15
cilefen CreditAttribution: cilefen commentedUpdated the local tasks test base. We still needs the other link types.
Comment #16
cilefen CreditAttribution: cilefen commentedComment #17
cilefen CreditAttribution: cilefen commentedlinks.contextual. I am not dealing with mentions in comments yet.
Comment #18
cilefen CreditAttribution: cilefen commentedComment #19
cilefen CreditAttribution: cilefen commentedlinks.menu
Todo: links.action, comment mentions, and change records.
Comment #20
cilefen CreditAttribution: cilefen commentedComment #21
cilefen CreditAttribution: cilefen commentedlinks.action
Todo: comment mentions and change records.
Comment #22
dawehnerThis looks really good so far!
It maybe makes sense to postpone the links.menu_link changes, given that this will conflict with the menu link patches, like #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage
Comment #23
cilefen CreditAttribution: cilefen commentedFound a few of the comments, but may have missed a few.
Todo: change records. Postpone all or part on #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage if necessary, depending on the impact on that issue.
Comment #24
dawehnerI would be fine with temporarily moving just the three types.
Comment #25
cilefen CreditAttribution: cilefen commentedThis patch is meant to address only:
*.links.menu
is being postponed.Todo:
*.links.menu
that is postponed on #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage.Comment #26
cilefen CreditAttribution: cilefen commentedThe affected change records to be updated and referred-to are:
Comment #27
cilefen CreditAttribution: cilefen commentedDraft change notice: https://www.drupal.org/node/2302893
Comment #28
dawehnerThe change notice coverage looks fine as well as the patch.
Comment #29
tim.plunkett+1
Comment #30
sunFWIW, contextual (module) appearing in that list implies that contrib modules are supposed to advance on this pattern by using their own suffix.
At the same time, the suffixes "action", "task", and "menu" do not correlate to a module, but are sorta "reserved" by Drupal core.
I assume that is intended, but worth to point out.
Comment #31
cilefen CreditAttribution: cilefen commented@sun Contrib modules must use the new names. Maybe we could be clearer on that in the change record.
Comment #32
cilefen CreditAttribution: cilefen commented@sun Oh sorry I misunderstood your comment.
Comment #33
neclimdulSorry for finding this so late in the discussion. To me, this implies some connection between these system that are pretty disparate. Putting links on the page is just something we do because we write HTML. Ditto on routing.yml, everything is going to point to that, because that's the core of our system.
I guess I just want to make sure we are sure we're not doing this based on the history of hook_menu and our biases as experienced Drupal developers rather then actual clarity.
Comment #34
effulgentsia CreditAttribution: effulgentsia commentedIf we consider our other module-level YAML files, we have .info.yml, .routing.yml, .services.yml, .libraries.yml, and maybe eventually .events.yml. Those are much more disparate concepts than what variants of link groups are to each other. So I think them staying separate files is a good enough acknowledgement of their disparateness, but putting them all under a common "links" namespace is a good way to group them conceptually.
Well, I think
menu
is also well named, as that relates to the \Drupal\Core\Menu component. I supposeaction
andtask
aren't properly namespaced and are just being grandfathered in: similar problem we have elsewhere in core (e.g., adate_format
entity type). Since the lack of component or module namespace for 'local_tasks' and 'local_actions' is a preexisting condition of HEAD, I don't think this patch makes the problem any worse.Comment #35
alexpottOkay let's get this in whilst the patch applies and we've got no new files.
Committed f2b6aa7 and pushed to 8.x. Thanks!
Comment #36
sunThanks! This is definitely an improvement to status quo and improves DX.
I would, however, recommend to leave the door open for further improvements. To improve consistency of definitions across files (cf. #4), but also, to discuss and consider a potential merge of e.g. actions and tasks into a single file, in separate issues.
Comment #38
alexpottWe need to fix documentation as well eg. https://www.drupal.org/search/site/local_tasks.yml?f[0]=ss_meta_type%3Ad...
Comment #39
Gábor HojtsyThe https://www.drupal.org/node/2122231 page is a good starting point, since that search does not seem to yield any results.
Comment #40
dawehnerHopefully all pages are covered
Comment #41
lussolucahttps://www.drupal.org/node/2302893 mention that also *.menu_links.yml has been renamed to *.links.menu.yml but this seems not true.
Comment #42
cilefen CreditAttribution: cilefen commented@lussoluca You are correct about that.
Comment #43
cilefen CreditAttribution: cilefen commentedFollowup for links.menu #2303605: Rename *.menu_links.yml to *.links.menu.yml files to improve DX.
Comment #44
cilefen CreditAttribution: cilefen commentedIs it proper form to update superseded change records?
https://www.drupal.org/node/2302893 references old change records that may need updating if that is true.
Comment #45
Gábor HojtsyUpdated the D8 code in potx translation parser: #2305555: All the links files got renamed in Drupal 8
Comment #46
effulgentsia CreditAttribution: effulgentsia commentedYes.
Comment #47
cilefen CreditAttribution: cilefen commentedUpdated the prior change records. Can someone give them a quick review, update the title of this issue, and mark this "fixed"?
The prior notices are linked from this one:
https://www.drupal.org/node/2302893
Comment #48
cilefen CreditAttribution: cilefen commentedComment #49
dawehnerThese updates looks perfect.
Comment #50
cilefen CreditAttribution: cilefen commented