You are here

function globallink_menu_local_tasks_alter in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink.module \globallink_menu_local_tasks_alter()
  2. 7.6 globallink.module \globallink_menu_local_tasks_alter()

Implements hook_menu_local_tasks_alter().

File

./globallink.module, line 954
GlobalLink translation module.

Code

function globallink_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  $node_check = variable_get('globallink_implementation_type', 0);
  if ($root_path != 'node/%/translate') {
    return;
  }
  if (!preg_match("!^node/(\\d+)(/.+|)\$!", $router_item['href'], $matches)) {
    return;
  }
  if ($node = node_load((int) $matches[1])) {
    $nid = $node->tnid;
    if ($node->tnid == 0) {
      $nid = $node->nid;
    }
    if (translation_supported_type($node->type)) {
      $send_link = 'admin/globallink-translations/dashboard';
      $active_link = 'admin/globallink-translations/activeSubmissions';
    }
    elseif (entity_translation_node_supported_type($node->type)) {
      $send_link = 'admin/globallink-translations/dashboard/entity';
      $active_link = 'admin/globallink-translations/activeSubmissions/entity';
    }
    else {
      return;
    }
    if ($node_check == 1) {
      if (!globallink_is_node_translatable(node_load($nid))) {
        return;
      }
    }
    $pending = TRUE;
    $source = language_default()->language;
    $t_nodes = translation_node_get_translations($nid);
    if (count($t_nodes) > 0) {
      if (isset($t_nodes[$source])) {
        unset($t_nodes[$source]);
        $langs = language_list();
        unset($langs[$source]);
        if (count($langs) > 0) {
          $tgt_arr = globallink_get_tpt_sent_rows($nid, $source);
          $tpt_count = count($tgt_arr);
          if ($tpt_count > 0 && $tpt_count == count($langs)) {
            $pending = FALSE;
          }
        }
      }
    }
    $data['actions']['output']['globallink'] = array(
      '#theme' => 'menu_local_action',
      '#link' => array(),
    );
    if ($pending) {
      if (user_access(TPT_ROLE_MANAGE_TRANSLATIONS) || user_access(TPT_ROLE_DO_TRANSLATIONS)) {
        $data['actions']['output']['globallink']['#link']['title'] = t('Send for translation');
        $data['actions']['output']['globallink']['#link']['href'] = $send_link;
        $data['actions']['output']['globallink']['#link']['localized_options'] = array(
          'query' => array(
            'rnid' => $nid,
          ),
        );
      }
    }
    else {
      $data['actions']['output']['globallink']['#link']['title'] = t('This content has been sent out for translation.');
      $data['actions']['output']['globallink']['#link']['href'] = $active_link;
      $data['actions']['output']['globallink']['#link']['localized_options'] = array(
        'query' => array(
          'rnid' => $nid,
        ),
      );
    }
  }
}