Custom Menu Link - How to change the symbol

Hi @RolandLocke - welcome to the forum! :smiley:

I merged your question into this post, to keep them together for future readers.

Yea hook_page_attachments() or hook_page_attachments_alter() is another way to do it!

The basic principle is the same: you want to use a Drupal hook (a specially named function) to attach your library (CSS) to all pages that have the menu, so that it gets included and styles the icon the way you want. There are various hooks that could be used for this purpose, and the ā€œpage attachmentsā€ ones work because they essentially run on every page load, so you’re pretty guaranteed to get your code included everywhere you need it.

Using a preprocess hook, as described earlier, is a more ā€œtargetedā€ way of doing the same thing. Essentially, instead of saying ā€œadd this CSS to every pageā€, a preprocess hook can say ā€œadd this CSS whenever the toolbar is built.ā€ The toolbar is ultimately what you’re trying to modify, so using hook_preprocess_toolbar() is probably the ā€œbestā€ way to do it, but both will work.

I’m not sure why @SirSundays’s hook wasn’t working, but here is another example in a community module that uses hook_preprocess_toolbar(), and I know for a fact that this works:

That adds this library: farm_regen_digital/farm_regen_digital.libraries.yml at 1.x Ā· Regen-Digital/farm_regen_digital Ā· GitHub

… which adds this CSS: farm_regen_digital/css/toolbar.css at 1.x Ā· Regen-Digital/farm_regen_digital Ā· GitHub

Note: that CSS does two things… adjusts the logo size and spacing (because the module also replaces the default farmOS logo), and it styles the ā€œIntegrationsā€ icon (on a related note, we are considering moving this ā€œIntegrationsā€ menu item into core: Integrations menu?).

Hope that helps!

1 Like