Hello,

In order to create an "Add Gallery" action-link on the Galleries page I have implemented hook_menu_local_tasks like this:

<?php 
function mymodule__menu_local_tasks_alter(&$data, $router_item, $root_path) { 
  if ($root_path == 'taxonomy/term/%') {  
    $item = menu_get_item('node/add/media-gallery');
    $item['title'] = t('Add gallery');
    $data['actions']['output'][] = array(
      '#theme' => 'menu_local_action',
      '#link' => $item,
    );
  }
}
?>

As you can see on the attached screenshot, the link appears twice on the page.

Can someone please tell me what I'm doing wrong?

CommentFileSizeAuthor
add-gallery.jpg13.67 KBrombapa

Comments

rombapa’s picture

Answering my own question: it seems that the implementation of hook_menu_local_tasks_alter is called twice: first for the tabs and second for the actions. So Before adding the action link, I test whether $data['actions']['output'] is empty:

<?php
function mymodule_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($root_path == 'taxonomy/term/%' && sizeof($data['actions']['output']) == 0) {  // note the second condition
    $item = menu_get_item('node/add/media-gallery');
    $item['title'] = t('Add gallery');
    $data['actions']['output'][] = array(
      '#theme' => 'menu_local_action',
      '#link' => $item,
    );
  }  
}
?>

All suggestions/remarks are very welcome :-)

rombapa’s picture

Correcting my own answer :)...

A 3rd condition is needed so that the Add Gallery link doesn't display for anonymous users

<?php
function mymodule_menu_local_tasks_alter(&$data, $router_item, $root_path) {

  if ($root_path == 'taxonomy/term/%' && sizeof($data['actions']['output']) == 0 && user_access('create media_gallery content')) {    // note 3rd cond.
    $item = menu_get_item('node/add/media-gallery');
    $item['title'] = t('Add gallery');
    $data['actions']['output'][] = array(
      '#theme' => 'menu_local_action',
      '#link' => $item,
    );
  } 
}
?>
lsolesen’s picture

Status: Active » Fixed

Marking this as fixed, as it seems you answered your own answer?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.