You are here

function mb_content_menu_local_tasks_alter in More Buttons 7

Implements hook_menu_local_tasks_alter().

Alter the node local tasks to

  • use an destination parameter
  • provide the "Create new" tab.

File

mb_content/mb_content.module, line 301
Provides additional buttons for nodes.

Code

function mb_content_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  global $base_url;
  $destination = drupal_get_destination();
  $module = 'mb_content';
  if ($router_item['tab_root'] == 'node/%') {
    $node = $router_item['map'][1];
    $node_type_name = node_type_get_name($node);

    // Add Create new as local task tab.
    // Note: access_callback no works.
    if (variable_get('mb_content_tabcn_' . $node->type, 0) == 1) {

      // Note: The weight setting are not accepted.
      // Organize the proper tab weight for the new "Create new" tab to display the new tab on the right position.
      $holder = array();

      // User with node edit permission. The tabs are displayed and the Edit tab exists.
      if (isset($data['tabs'][0]['output'][1]) && $data['tabs'][0]['output'][1]['#link']['page_callback'] == 'node_page_edit') {
        $holder = array_splice($data['tabs'][0]['output'], 2);
      }
      elseif (isset($data['tabs'][0]['output'][1]) && $data['tabs'][0]['output'][1]['#link']['page_callback'] != 'node_page_edit') {
        $holder = array_splice($data['tabs'][0]['output'], 1);
      }

      // Insert the new tab.
      $data['tabs'][0]['output'][] = array(
        '#theme' => 'menu_local_task',
        '#link' => array(
          'title' => mb_content_createnew_title(),
          'href' => 'node/add/' . $node->type,
          'tab_root_href' => 'node/' . $node->nid,
          'weight' => 2,
          'localized_options' => array(
            'attributes' => array(
              'title' => t('Create new @content', array(
                '@content' => t($node_type_name),
              )),
            ),
          ),
        ),
      );

      // Rebuild the tabs to display all tabs.
      $data['tabs'][0]['output'] = array_merge($data['tabs'][0]['output'], $holder);
    }

    // Add Create new as action link.
    if ($root_path == 'node/%/edit' && variable_get('mb_content_tabcn_' . $node->type, 0) == 2) {
      $css_node_type = str_replace('_', '-', $node->type);
      $item = menu_get_item('node/add/' . $node->type);
      $item['title'] = t('Create new @content', array(
        '@content' => t($node_type_name),
      ));
      $item['localized_options']['attributes']['class'] = array(
        'node-action-link',
        'node-action-link-' . $css_node_type,
      );
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }
}