On a normal overview page most off the time you have an action link (from $action_links), like 'add content'.
How can i add a link like this on a custom view i created?

Comments

ericclaeren’s picture

Did you found an answer on your question? I'm searching for a solution as well.

ericclaeren’s picture

Thank you jessicwill for your contribution, i found it really helpful.

My solution: a custom module with the following hook:

function YOURMODULENAME_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  switch($root_path){  
    case 'path_of_your_page' : // for example 'page/view/news'
      $item = menu_get_item('node/add'); 
      if ($item['access']) {       
        $data['actions']['output'][] = array(
          '#theme' => 'menu_local_action',
          '#link' => $item,
        );
      }
    break;  
  }  
}

Make sure $action_links are printed in your theme's page.tpl.php

<?php if ($action_links): ?>
  <ul class="action-links"><?php print render($action_links); ?></ul>
<?php endif; ?>
svdhout’s picture

Thx, that works for me

7wonders’s picture

But it doesnt work with views?

wwgrey’s picture

Maybe article http://drupal.org/node/1517916 can help ?

jcfiala’s picture

Adding the bit about $action_links being printed in the theme was really helpful - that ended up being the problem!

--
-john

mathieso’s picture

This worked for adding actions to a view:

function cyco_exercises_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  switch($root_path){
    case 'exercises':
      //Link to add exercise.
      $item = menu_get_item('node/add/exercise');
      $item['title'] = t('Add exercise');
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
      //Link to add rubric item.
      $item = menu_get_item('node/add/rubric-item');
      $item['title'] = t('Add rubric item');
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
      break;
  }
}
ashuaviator1987’s picture

I have a view for user/%/article-posted and trying to add a button for 'Add a Blog'.I used the below code.


function custom_action_links_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  switch($root_path){
    case 'user/*/article-posted':
      //Link to add exercise.
      $item = menu_get_item('node/add/blog');
      $item['title'] = t('Add Blog');
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      ); 
      break;
  }
}

I also tried


function custom_action_links_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  switch($root_path){
    case 'user/%/article-posted':
      //Link to add exercise.
      $item = menu_get_item('node/add/blog');
      $item['title'] = t('Add Blog');
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      ); 
      break;
  }
}

But none of these seem to work

capysara’s picture

I just wanted to reuse an existing action link for Add file, so this worked for me:

I added a Header to my view using Global: unfiltered text.

<ul class="action-links">
<a href='/file/add'>Add file</a>