You are here

function party_menu_local_tasks_alter in Party 8.2

Same name and namespace in other branches
  1. 7 party.module \party_menu_local_tasks_alter()

Implements hook_menu_local_tasks_alter().

Adds local tasks in the following places:

  • to add a party from the party list admin page
  • to add/import a new data set (ie entity bundle) from the data sets admin page
  • to add new entities on a party piece that's based on a data set

File

./party.module, line 305
Provides a generic CRM party entity.

Code

function party_menu_local_tasks_alter(&$data, $router_item, $root_path) {

  // Add action link to 'party/add' on 'admin/community/list' page.
  if ($root_path == 'admin/community/list' || $root_path == 'admin/community') {
    $item = menu_get_item('party/add');
    if ($item['access']) {
      $data['actions']['output'][] = array(
        '#theme' => 'menu_local_action',
        '#link' => $item,
      );
    }
  }

  // Add action links to 'admin/community/datasets' page.
  if ($root_path == 'admin/community/datasets') {
    $data_sets = party_get_data_set_info();
    $attached_entity_types = array();
    foreach ($data_sets as $data_set) {
      $attached_entity_types[$data_set['entity type']] = $data_set['admin'];
    }
    foreach ($attached_entity_types as $type => $admin) {
      $type = entity_get_info($type);
      if (isset($admin['create'])) {
        $item = menu_get_item($admin['create']);
        if ($item['access']) {
          $item['title'] = 'Add ' . $type['label'] . ' data set';
          $item['localized_options'] = array(
            'query' => array(
              'destination' => 'admin/community/datasets',
            ),
          );
          $data['actions']['output'][] = array(
            '#theme' => 'menu_local_action',
            '#link' => $item,
          );
        }
      }
      if (isset($admin['import'])) {
        $item = menu_get_item($admin['import']);
        $item['localized_options'] = array(
          'query' => array(
            'destination' => 'admin/community/datasets',
          ),
        );
        $item['title'] = 'Import ' . $type['label'] . ' data set';
        if ($item['access']) {
          $data['actions']['output'][] = array(
            '#theme' => 'menu_local_action',
            '#link' => $item,
          );
        }
      }
    }
  }

  // Add action links for attaching new entities on party pieces that are built
  // from data sets.
  if (substr($root_path, 0, 8) == 'party/%/') {
    if (!isset($router_item['original_map'][3])) {
      $piece_subpath = $router_item['original_map'][2];
      $pieces = party_get_party_piece_info();
      if (!isset($pieces[$piece_subpath])) {
        return;
      }
      $piece = $pieces[$piece_subpath];
      if (isset($piece['data_set'])) {
        $data_set_base_path = implode('/', $router_item['original_map']);
        $data_set = party_get_data_set_info($piece['data_set']);
        foreach ($data_set['actions'] as $action => $action_info) {
          $item = menu_get_item($data_set_base_path . '/' . $action);

          // Menu access checks party_access(), which checks whether actions are
          // allowed by the data set definition.
          if ($item['access']) {
            $data['actions']['output'][] = array(
              '#theme' => 'menu_local_action',
              '#link' => array(
                'title' => t($action_info['action label'], array(
                  '@data-set' => $data_set['label'],
                )),
                'href' => $data_set_base_path . '/' . $action,
              ),
            );
          }
        }
      }
    }
  }
}