1

I am writing a custom module for my project which handles a list of content (from custom db table) and content addition, following is my code.

function cp_menu() {
    $items = array();
    $items['admin/structure/package'] = array(
    'title' => t('Packages'),
        'page callback' => 'cp_packages_list',
        'access arguments' => array('administer access control'),
        'description' => t('Packages'),
        'type' => MENU_CALLBACK,
    );
    $items['admin/structure/package/add'] = array(
    'title' => t('Add package'),
        'page callback' => 'cp_form',
        'access arguments' => array('administer access control'),
        'description' => t('Add package'),
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function cp_packages_list(){
    return 'this is a test page';
}
function cp_form() {
    return array('#markup'=>drupal_get_form('cp_my_form'));
}

it is working properly, but i want to show action links (add content type) at top of page like enter image description here

How can i add action links on page?

my action links would be 'Add package' and 'View orders'

1
$items['admin/structure/types'] = array(
    'title' => 'Content types',
    'description' => 'Manage content types, including default status, front page promotion, comment settings, etc.',
    'page callback' => 'node_overview_types',
    'access arguments' => array('administer content types'),
    'file' => 'content_types.inc',
  );
  $items['admin/structure/types/list'] = array(
    'title' => 'List',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/structure/types/add'] = array(
    'title' => 'Add content type',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('node_type_form'),
    'access arguments' => array('administer content types'),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'content_types.inc',
  );

This is what exist on node.module, modify to set the type to MENU_LOCAL_ACTION

Hope that help.

| improve this answer | |
  • It helps me to understand the menu structure but i am still not able to add action links. – Vikram Dec 6 '14 at 7:01
0

You can use hook_menu_local_tasks_alter() to add action links on any page.

Output that $root_path to see what it is on a page, it is not the same as the actual path necessarily.

function YOURMODULE_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  switch($root_path){
    case 'admin/structure/%':
      if ($router_item['original_map'][2] == 'path_arg') {
        $item = menu_get_item('admin/structure/types/add'); 
        if ($item['access']) {       
          $data['actions']['output'][] = array(
            '#theme' => 'menu_local_action',
            '#link' => $item,
          );
        }
      }
    break;  
  }  
}

Credit to answer on d.o

| improve this answer | |

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.