You are here

function lingotek_pm in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.2 lingotek.page.inc \lingotek_pm()
  2. 7.3 lingotek.page.inc \lingotek_pm()
  3. 7.4 lingotek.page.inc \lingotek_pm()
  4. 7.5 lingotek.page.inc \lingotek_pm()
  5. 7.6 lingotek.page.inc \lingotek_pm()

Page callback for the Lingotek local task on node detail pages.

Construct the table summarizing information a Product Manager would want to know about the progress of the translations.

Return value

array A Drupal render array of the page contents.

1 string reference to 'lingotek_pm'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.page.inc, line 324
Lingotek Tab for Nodes

Code

function lingotek_pm($node) {
  $storage_method = $node->lingotek['lingotek_nodes_translation_method'];
  if (lingotek_managed_by_entity_translation($node->type) && $storage_method == 'field') {
    $handler = entity_translation_get_handler('node', $node);
    $handler
      ->initPathScheme();

    // Initialize translations if they are empty.
    $translations = $handler
      ->getTranslations();
    if (empty($translations->original)) {
      $handler
        ->initTranslations();
      $handler
        ->saveTranslations();
    }
  }

  // Display all of the appropriate node management sections (e.g., Upload, Download, Publish)
  $output = array(
    '#attached' => array(
      'css' => array(
        '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css' => array(
          'type' => 'external',
        ),
      ),
    ),
  );

  // node translation support
  if ($node->tnid != 0 && $node->tnid != $node->nid) {
    $output[] = array(
      '#markup' => t('This is a translated node. Go to the <a href="@link">source node</a> to manage the translations.', array(
        '@link' => url('node/' . $node->tnid . '/lingotek_pm'),
      )),
    );
    return $output;
  }

  // node disabled support
  if ($node->lingotek['profile'] == LingotekSync::PROFILE_DISABLED) {
    $output[] = array(
      '#markup' => t('Lingotek Translation is currently disabled for this node. You can enable translation by editing this node and selecting a Translation Profile (e.g. "Automatic").'),
    );
    return $output;
  }
  if (isset($node->lingotek['upload_status']) && $node->lingotek['upload_status'] == LingotekSync::STATUS_NONE || !isset($node->lingotek['upload_status'])) {
    $content_push_form = drupal_get_form('lingotek_push_form', $node);
    $output['content_push'] = array(
      '#markup' => drupal_render($content_push_form),
    );
    return $output;
  }
  if (lingotek_supported_node($node) && Lingotek::isSupportedLanguage($node->language)) {
    if (isset($node->lingotek['upload_status']) && $node->lingotek['upload_status'] == LingotekSync::STATUS_EDITED) {
      $content_push_form = drupal_get_form('lingotek_push_form', $node);
      $output['content_push'] = array(
        '#markup' => drupal_render($content_push_form),
      );
    }
    if (!empty($node->lingotek['document_id'])) {
      $document = LingotekDocument::load($node->lingotek['document_id']);
      $progress = $document
        ->getProgress();
      if (!empty($progress->results) && $progress->results === 'success') {
        $download_form = drupal_get_form('lingotek_download_translations_form', $node, $document);
        $output[] = array(
          '#markup' => drupal_render($download_form),
        );
        if ($document
          ->hasPhasesToComplete()) {

          // Add the mark as complete table if there are complete-eligible phrases.
          $drupal_phase_complete_from = drupal_get_form('lingotek_mark_phases_complete', $node, $document);
          $output['mark_complete'] = array(
            '#markup' => drupal_render($drupal_phase_complete_from),
          );
        }
        $lingotek_advanced_parsing_form = drupal_get_form('lingotek_advanced_parsing_upgrade_form');
        $output['upgrade_form'] = array(
          '#markup' => drupal_render($lingotek_advanced_parsing_form),
        );
      }
      else {

        // Document not found (may still be importing)
        // Import Status (check and report on import status)
        $status = $document
          ->getImportStatus();
        $message = t('Content Import Status:') . ' <i>' . $status . '</i> ' . l('<i class="fa fa-refresh"></i> ' . t('Refresh'), '', array(
          'html' => TRUE,
          'attributes' => array(
            'class' => 'ltk-icon',
            'title' => t('Refresh'),
            'onclick' => array(
              'location.reload();return false;',
            ),
          ),
        ));

        // Coder review error: we don't want to translate font awesome classes.
        drupal_set_message(filter_xss($message), 'status');
        $output['import_status'] = array(
          '#type' => 'fieldset',
          '#title' => t('Content Import Status'),
          '#description' => filter_xss($message),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
      }

      /* REMOVE DISASSOCIATE_TRANSLTIONS FORM FROM THE TRANSLATE PAGE, FOR NOW
         $disassociate_translations_form = drupal_get_form('lingotek_entity_disassociate_form', $node->nid);
         $output['disassociate_translations'] = array(
           '#markup' => drupal_render($disassociate_translations_form),
         );
         */
    }
  }
  else {
    $output[] = array(
      '#markup' => '<p class="help">' . t('This node is not compatible with Lingotek translation. Either it is not a Lingotek tranlsation-enabled content type or the node does not have a defined language.') . '</p>',
    );
  }

  // Publish form
  $output['publish_form'] = drupal_get_form('lingotek_publish_form', $node);
  return $output;
}