You are here

function i18n_access_translation_node_overview in Translation Access 7

Same name and namespace in other branches
  1. 6 i18n_access.module \i18n_access_translation_node_overview()
1 string reference to 'i18n_access_translation_node_overview'
i18n_access_menu_alter in ./i18n_access.module
Implements hook_menu_alter().

File

./i18n_access.module, line 219
file_description

Code

function i18n_access_translation_node_overview($node) {
  include_once DRUPAL_ROOT . '/includes/language.inc';
  if (!empty($node->tnid)) {

    // Already part of a set, grab that set.
    $tnid = $node->tnid;
    $translations = translation_node_get_translations($node->tnid);
  }
  else {

    // We have no translation source nid, this could be a new set, emulate that.
    $tnid = $node->nid;
    $translations = array(
      $node->language => $node,
    );
  }
  $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
  $header = array(
    t('Language'),
    t('Title'),
    t('Status'),
    t('Operations'),
  );

  //added from i18n/i18n_node/i18n_node.pages.inc function
  global $user;
  $account = $user;
  $perms = i18n_access_load_permissions($account->uid);

  //end

  // Modes have different allowed languages
  foreach (i18n_node_language_list($node) as $langcode => $language_name) {
    if ($langcode == LANGUAGE_NONE) {

      // Never show language neutral on the overview.
      continue;
    }
    $options = array();
    if (isset($translations[$langcode])) {

      // Existing translation in the translation set: display status.
      // We load the full node to check whether the user can edit it.
      $translation_node = node_load($translations[$langcode]->nid);
      $path = 'node/' . $translation_node->nid;
      $title = i18n_node_translation_link($translation_node->title, $path, $langcode);
      if (node_access('update', $translation_node)) {
        $text = t('edit');
        $path = 'node/' . $translation_node->nid . '/edit';
        $options[] = i18n_node_translation_link($text, $path, $langcode);
      }
      $status = $translation_node->status ? t('Published') : t('Not published');
      $status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : '';
      if ($translation_node->nid == $tnid) {
        $language_name = t('<strong>@language_name</strong> (source)', array(
          '@language_name' => $language_name,
        ));
      }
    }
    else {

      // No such translation in the set yet: help user to create it.
      $title = t('n/a');
      if (node_access('create', $node)) {
        $text = t('add translation');
        $path = 'node/add/' . str_replace('_', '-', $node->type);
        $query = array(
          'query' => array(
            'translation' => $node->nid,
            'target' => $langcode,
          ),
        );

        //condition added from i18n/i18n_node/i18n_node.pages.inc
        if (in_array($langcode, $perms)) {
          $options[] = i18n_node_translation_link($text, $path, $langcode, $query);
        }
      }
      $status = t('Not translated');
    }
    $rows[] = array(
      $language_name,
      $title,
      $status,
      implode(" | ", $options),
    );
  }
  drupal_set_title(t('Translations of %title', array(
    '%title' => $node->title,
  )), PASS_THROUGH);
  $build['translation_node_overview'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  if (user_access('administer content translations')) {
    $build['translation_node_select'] = drupal_get_form('i18n_node_select_translation', $node, $translations);
  }
  return $build;
}