You are here

function pmexpense_pm_contextual_links in Drupal PM (Project Management) 7.3

Implements hook_pm_contextual_links().

File

pmexpense/pmexpense.module, line 114
Hook implementations and main functions for PM Expense.

Code

function pmexpense_pm_contextual_links($entity, $type, $view_mode, $langcode) {
  $links = array();
  list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
  if ($type == 'node') {
    $field_info = field_info_field('pmexpense_parent');
    if (isset($field_info['settings']['handler_settings']['target_bundles'])) {
      $target_bundles = $field_info['settings']['handler_settings']['target_bundles'];
    }
    else {
      $target_bundles = array(
        'pmproject',
        'pmorganization',
        'pmtask',
        'pmticket',
        'pmissue',
      );
    }
    if (in_array($bundle, $target_bundles)) {
      $links[t('Add Expense')] = array(
        'title' => t('Add Expense'),
        'href' => 'node/add/pmexpense',
        'query' => array(
          'pmexpense_parent' => $id,
        ),
      );
    }
  }
  return $links;
}