Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

It looks like the other answer on that post you linked topost you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

However, I'm not sure if that solution would work for manually-created menu links items with custom title text. The other, possibly more universal, option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable (when the link is saved), and the latter is used to actually alter it (at render time).

Actually, it looks like this postthis post covers both these options in even more detail, so I won't repeat any of their code samples here.

This distinction about which alter hooks fire at save/cache-clear time vs. render time is important as it often means that you have to leverage a hook + callback, or 2 hooks, to implement dynamic alterations. For example, if you choose the second option you use hook_menu_link_alter() to declare the link as alterable, and though that hook does not fire each time the link is rendered, it "registers" the fact that hook_translated_menu_link_alter() should in fact be called at render time for that specific link.

It looks like the other answer on that post you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

However, I'm not sure if that solution would work for manually-created menu links items with custom title text. The other, possibly more universal, option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable (when the link is saved), and the latter is used to actually alter it (at render time).

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

This distinction about which alter hooks fire at save/cache-clear time vs. render time is important as it often means that you have to leverage a hook + callback, or 2 hooks, to implement dynamic alterations. For example, if you choose the second option you use hook_menu_link_alter() to declare the link as alterable, and though that hook does not fire each time the link is rendered, it "registers" the fact that hook_translated_menu_link_alter() should in fact be called at render time for that specific link.

It looks like the other answer on that post you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

However, I'm not sure if that solution would work for manually-created menu links items with custom title text. The other, possibly more universal, option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable (when the link is saved), and the latter is used to actually alter it (at render time).

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

This distinction about which alter hooks fire at save/cache-clear time vs. render time is important as it often means that you have to leverage a hook + callback, or 2 hooks, to implement dynamic alterations. For example, if you choose the second option you use hook_menu_link_alter() to declare the link as alterable, and though that hook does not fire each time the link is rendered, it "registers" the fact that hook_translated_menu_link_alter() should in fact be called at render time for that specific link.

Clarified the fact that some alter hooks don't fire at render time, but that's ok. Also removed last paragraph which was maybe tl:dr.
Source Link
rjacobs
  • 2.4k
  • 1
  • 14
  • 15

It looks like the otherother answer on that post you linked to is quite relevant. It references hook_menu_alter()hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

However, I'm not sure if that solution would work for manually-created menu links items with custom title text. The other, possibly more universal, option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable on save(when the link is saved), and the latter is used to actually alter it at render time. This distinction about which alter hooks fire at save or cache-clear time vs.(at render time is important as it often means that you have to leverage 2 hooks, or a hook + callback to make dynamic alterations).

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

I the case where you are just altering the title, I supposeThis distinction about which alter hooks fire at save/cache-clear time vs. render time is important as it often means that setting upyou have to leverage a custom titlehook + callback with hook_menu_alter() makes the most sense, or 2 hooks, to implement dynamic alterations. TheFor example, if you choose the second option you use hook_menu_link_alter() along withto declare the link as alterable, and though that hook does not fire each time the link is rendered, it "registers" the fact that hook_translated_menu_link_alter() option mayshould in fact be a bit more heavy-handed and probably better suited to cases where you need to alter the actual URL orcalled at render time for that specific link attributes dynamically.

It looks like the other answer on that post you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

The other option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable on save, and the latter is used to actually alter it at render time. This distinction about which alter hooks fire at save or cache-clear time vs. render time is important as it often means that you have to leverage 2 hooks, or a hook + callback to make dynamic alterations.

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

I the case where you are just altering the title, I suppose that setting up a custom title callback with hook_menu_alter() makes the most sense. The hook_menu_link_alter() along with hook_translated_menu_link_alter() option may be a bit more heavy-handed and probably better suited to cases where you need to alter the actual URL or link attributes dynamically.

It looks like the other answer on that post you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

However, I'm not sure if that solution would work for manually-created menu links items with custom title text. The other, possibly more universal, option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable (when the link is saved), and the latter is used to actually alter it (at render time).

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

This distinction about which alter hooks fire at save/cache-clear time vs. render time is important as it often means that you have to leverage a hook + callback, or 2 hooks, to implement dynamic alterations. For example, if you choose the second option you use hook_menu_link_alter() to declare the link as alterable, and though that hook does not fire each time the link is rendered, it "registers" the fact that hook_translated_menu_link_alter() should in fact be called at render time for that specific link.

Source Link
rjacobs
  • 2.4k
  • 1
  • 14
  • 15

It looks like the other answer on that post you linked to is quite relevant. It references hook_menu_alter() as a tool to:

... add a title callback that will be called every time a link to the menu item will be rendered

The other option that I can think of is using hook_menu_link_alter() along with hook_translated_menu_link_alter(). The former is used to "flag" a link as alterable on save, and the latter is used to actually alter it at render time. This distinction about which alter hooks fire at save or cache-clear time vs. render time is important as it often means that you have to leverage 2 hooks, or a hook + callback to make dynamic alterations.

Actually, it looks like this post covers both these options in even more detail, so I won't repeat any of their code samples here.

I the case where you are just altering the title, I suppose that setting up a custom title callback with hook_menu_alter() makes the most sense. The hook_menu_link_alter() along with hook_translated_menu_link_alter() option may be a bit more heavy-handed and probably better suited to cases where you need to alter the actual URL or link attributes dynamically.