The "rolling patch" in #1137920: Fix toolbar on small screen sizes and redesign toolbar for desktop defines a new hook so that other modules can add their own menus to the toolbar. This hook should be documented in toolbar.api.php
. If the Toolbar module implements its own hook, then it will serve as an example for other modules and also simplify the code in toolbar_view()
.
While working on this, I intend to do additional code review and clean-up. I am considering changing the name of the hook from hook_toolbar_register_tabs()
to hook_toolbar()
, following the pattern of hook_menu()
. I am also considering adding hook_toolbar_alter()
, unless this introduces a performance hit.
Development
I do not plan to post patches on this issue. Instead, development will take place in http://drupal.org/sandbox/jessebeach/1749042, the same sandbox as #1137920: Fix toolbar on small screen sizes and redesign toolbar for desktop. Any progress made here will be incorporated into the "rolling patches" posted there.
Comment | File | Size | Author |
---|---|---|---|
#15 | toolbar-hooks-1830526-15-do-not-test.patch | 565 bytes | benjifisher |
Comments
Comment #1
benjifisherFirst commit: f464d29.
I added
toolbar_toolbar_register_tabs()
, moving some code out oftoolbar_view()
. I also made some smaller changes:drupal_sort_weight()
. (I assigned Home and Menu the weights -10 and -5, respectively.)Comment #2
benjifisherSecond commit: a116440.
Changed the hook name from
hook_toolbar_register_tabs()
tohook_toolbar()
and addedhook_toolbar_alter()
. If we decide this is a bad idea, we can cherry-pick this out.Comment #3
benjifisherThird commit: 1d156df.
Code clean-up in
toolbar_view()
.Comment #4
benjifisherCommit 8d87a02.
In
hook_toolbar()
, change$tab
to$items
as inhook_menu()
.Comment #5
benjifisherCommit 4c30b08.
Add hook documentation in the new file
toolbar.api.php
.I did my best, but I hope others will add to the documentation. In particular, we should document the caching mechanism (maybe here). I am not sure how it works, but I notice that some changes do not take effect until I clear caches.
Comment #6
benjifisherCommit 264f8ac.
I edited the comments in
toolbar_view()
.What should
toolbar_view()
do if two (or more) modules use the same key (or category)?Until now,
Note that rthe commit in Comment #1 changes the interpretation of "second."
This commit modifies the behavior:
I do not claim that either of these is a good idea! We need some discussion here. What are the use cases?
In particular, the current code uses pre_render functions to define the trays for User and Shortcut. I think that these functions ignore any other entries in the render elements, so other modules cannot add to these menus without overriding the pre_render functions. Of course, we could rewrite those functions.
Comment #7
benjifisherCommit ceefb98.
Improved defaults for the tab render elements.
This commit has two effects that I can think of:
$tab['attributes']['class'] = array('tab')
, then the previous version would produce markup<a class="tab tab" ...>
This commit avoids doubling the 'tab' class.Comment #8
benjifisherCommit: 7ba8a76.
Add paths to Toolbar tabs.
If javascript is disabled, then the Menu, Shortcut, and User tabs should link to something useful, not the home page. I make Menu a link to
/admin
, Shortcut link to/admin/config/user-interface/shortcut
, and User link to/user
.Comment #9
benjifisherRegarding the questions in #6, compare with
hook_menu()
. Becausemenu_router_build()
usesarray_merge()
, the first module to define a given menu path inhook_menu()
wins:Comment #10
jessebeach CreditAttribution: jessebeach commented@benjifisher, great work so far! I've merged the changes in node/1830526-toolbar-hooks as of 7ba8a762c740408d7425efbb16653d59dc775151 into node/1137920-responsive-toolbar. You're code is leaps better than what I had and I think it'll help us in the effort to get it rtbc'ed. You'll want to rebase your branch on 1137920 with a fast-forward for further changes.
The only use-case I can think of is the Edit module or maybe something like Commerce that registers a top-level tab. I can't foresee yet why contrib will want to augment the Shortcut or User tray. In any case, merging the contents seems like the wrong strategy. I think we just want wholesale replacement of the content if a module defines an existing tray name. Hopefully modules will just use their own name which is avoid namespace clashing. I'm willing to let it be as it is and see what folks say in review.
Comment #11
benjifisher@jessebeach:
I am inclined to take the same approach as
hook_menu()
(see my comment #9 above). In other words, do not allow modifications inhook_toolbar()
. If another module wants to modify the User menu, it should implementhook_toolbar_alter()
. But I am open to other suggestions.How about these for use cases?
admin/user/user2
(I think), its alternative user-management page.Comment #12
jessebeach CreditAttribution: jessebeach commented@benjifisher. I'm mostly happy with what you put together in the branch and what's therefore been merged into #1137920. Did you want to do any refactoring before we put the code up for review through #1137920?
Comment #13
benjifisher@jessebeach:
I do not plan to do any more work on this branch without answers to some of the questions I posed in the comments. It seems unlikely that anyone else will offer opinions on them until the changes are reviewed as part of #1137920.
Short answer: no.
Comment #14
jessebeach CreditAttribution: jessebeach commentedAddressed in #1137920-216: Fix toolbar on small screen sizes and redesign toolbar for desktop.
Comment #15
benjifisherI found a typo (my fault). Please either apply this patch or cherry-pick 09820e3 from the sandbox.
Comment #16
jessebeach CreditAttribution: jessebeach commentedUpdated the spelling correction noted in #15 in the #1137920 issue.
Comment #17
benjifisherI checked the interdiff posted with #1137920-280: Fix toolbar on small screen sizes and redesign toolbar for desktop. The correction is there, so changing the status to Fixed.