1

When viewing a taxonomy term, I want to change the 'Edit' link (in the admin tabs) to say 'Edit this term' instead.

In taxonomy.module, the menu item is defined like this:

function taxonomy_menu() {
    $items['taxonomy/term/%taxonomy_term/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'drupal_get_form',
        // Pass a NULL argument to ensure that additional path components are not
        // passed to taxonomy_form_term() as the vocabulary machine name argument.
        'page arguments' => array('taxonomy_form_term', 2, NULL),
        'access callback' => 'taxonomy_term_edit_access',
        'access arguments' => array(2),
        'type' => MENU_LOCAL_TASK,
        'weight' => 10,
        'file' => 'taxonomy.admin.inc',
      );
}

So in my module, I try to do this:

function mymodule_menu_link_alter(&$item, $menu) {
  if ($item['link_path'] == 'taxonomy/term/%taxonomy_term/edit') {
    $item['link_title'] = 'Edit this term';
  };
}

After clearing cache and rebuilding menus, the menu item still says 'Edit'.

Is this because the menu item type is MENU_LOCAL_TASK? Or perhaps I am missing something else?

1

You're just implementing the wrong hook...you need hook_menu_alter() instead

function mymodule_menu_alter(&$items) {
  $items['taxonomy/term/%taxonomy_term/edit']['title'] = 'Edit this term';
}
2

hook_menu_link_alter() is invoked from menu_link_save(), which is the function called when a menu link is saved. The code you wrote for that hook would be invoked when, for example, you add a menu link from admin/structure/menu/manage/main-menu/add, and use taxonomy/term/%taxonomy_term/edit as value for Path.

As Clive said, hook_menu_alter() is the hook you should use to change the menu item defined in hook_menu() from a module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.