It's starting to become more widely supported to implement a hook_suppress($set = TRUE) that if triggered will not output anything 'special' that a module adds to a page (for us in modal callbacks, etc). This support is already implemented by admin_menu, admin, toolbar (via admin_select) and other modules. It would be good if we could universally support navbar as well. This hook is also used by the admin_select module to allow users to select the type of administration navigation they want to use if multiple options are available.
See related issues:
#675300: Provide a method to disable the output of the toolbar programmatically
#1125658: Add hook_suppress().
#1304540: Implement hook_suppress()
#1418930: Implement hook_suppress so olark isn't displayed in a modalframe.
Comment | File | Size | Author |
---|---|---|---|
#16 | navbar-suppress-1728726-n.patch | 1.82 KB | jessebeach |
#14 | interdiff.txt | 445 bytes | realityloop |
#14 | hook_suppress-1728726-14.patch | 1.98 KB | realityloop |
#12 | navbar-hook_suppress-1728726-12.patch | 1.98 KB | realityloop |
#2 | navbar-hook_suppress-1728726-2.patch | 2.03 KB | iler |
Comments
Comment #1
iler CreditAttribution: iler commentedThis patch adds support for hook_suppress().
Comment #2
iler CreditAttribution: iler commentedHere is revised patch against the current dev branch.
Comment #3
Dave ReidI'm curious why the JS part is needed? Most implementation of hook_suppress don't actually use any JS.
Comment #4
iler CreditAttribution: iler commentedI think that if someone calls the hook_suppress they don't want to display the unneeded JS either. This is the same way that hook_suppress is implemented in admin_menu.
Comment #5
jessebeach CreditAttribution: jessebeach commentedI'll get this in. Thanks for the patch!
Comment #6
jessebeach CreditAttribution: jessebeach commentedI don't understand. If I pass FALSE, as in I don't want the navbar to be supressed, then $suppress will be set to TRUE and the JS navbar behaviors will be aborted, but the Navbar HTML will still be outputed?
And if I pass TRUE, as in I want to suppress the navbar, then nothing is suppressed and the Navbar behaviors are run?
Also, if we suppress the navbar at during the render stage, let's say in pre_render, we won't need to knock out the JS because it just won't be loaded.
Dave Reid, I don't quite follow. Is the point of
hook_shutdown
to completely prevent a module from adding to the render pipeline? Should we usehook_shutdown
orhook_suppress
?Comment #7
Dave ReidSun would probably be the better one to explain why hook_suppress() is so odd. I didn't establish that pattern. Basically, calling
module_invoke_all('suppress', TRUE)
should cause all the modules to not display their output. At the latest possible stage, the individual modules will checkif (!mymodule_suppress())
before they add their output.hook_shutdown() is my mistake in the original report when I meant to type hook_suppress().
Comment #8
jessebeach CreditAttribution: jessebeach commentedI far as I understand, you end up delivering all the JS/CSS assets to the client and none of the HTML. I can't see a use case for this. Why would someone want to suppress output from any modules that happen to have this hook? It seems like you'd end up with a swiss-cheese page.
Comment #9
effulgentsia CreditAttribution: effulgentsia commentedI fixed the issue summary to say hook_suppress() rather than hook_shutdown(). This hook should not be needed in D8, because there should be better ways of controlling what does/doesn't get rendered in different conditions. This issue is filed for 7.x-1.x though, and for that, it seems reasonable.
Comment #10
Dave ReidThe usage is intended to ensure that we get a basic page, similar to overlay does without any kind of 'extra' stuff. This is also useful for modules like admin_select to allow specific users to pick which toolbar they have.
I don't see how the CSS and JS assets would be delivered if the suppression was enabled. The CSS/JS is added in the #attached library of the 'navbar' element type. That element is added in navbar_page_build(), which is where we're checking suppression. Am I missing elsewhere where any assets are added? Off hand this would like it prevents all JS from being added in the first place.
Comment #11
Dave ReidComment #11.0
Dave ReidFixed typo.
Comment #12
realityloopRerolled patch against current dev
Comment #13
Deciphered CreditAttribution: Deciphered commentedIndentation is all wrong.
Comment #14
realityloopUpdated patch attached (though have found that Navbar broken in other ways atm)
Comment #15
realityloopComment #16
jessebeach CreditAttribution: jessebeach commentedI took out the JavaScript code because these assets are not loaded if the Navbar element isn't placed in the render tree. So there's no need to alter the JS behavior.
Is that sufficient for what you need?
Comment #17
jessebeach CreditAttribution: jessebeach commentedAdded in e3389576b2539d79d9546b6fbd9b35ddd37c98fd
Comment #18
corbacho CreditAttribution: corbacho commentedJust for the record.
Admin menu module adds a JS setting in their hook_suppress, because admin_menu implements a special AJAX client-side caching . (Admin menu markup doesn't re-generate every page load).
Originally hook_suppress didn't have the JS setting, it was only added later on, with this feature #345984: Client-side caching of administration menu