You are here

function lingotek_form_node_form_alter in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.7 lingotek.module \lingotek_form_node_form_alter()
  2. 7.3 lingotek.module \lingotek_form_node_form_alter()
  3. 7.4 lingotek.module \lingotek_form_node_form_alter()
  4. 7.5 lingotek.module \lingotek_form_node_form_alter()
  5. 7.6 lingotek.module \lingotek_form_node_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

Parameters

array $form: A FAPI form array for the form being altered.

array $form_state: A FAPI form state array for the form being altered.

string $form_id: The ID of the form being altered.

File

./lingotek.module, line 509

Code

function lingotek_form_node_form_alter(&$form, $form_state, $form_id) {

  // On node create, set the language select box to our source language, if this is a node content type that we translate for, if the form is in Add mode.
  if (!isset($form['nid']['#value'])) {

    // add mode (no node id set)
    if (lingotek_supported_type($form['type']['#value'])) {

      // lingotek translated content type
      $form['language']['#default_value'] = lingotek_get_source_language();
    }
  }
  if (!lingotek_supported_type($form['#node']->type) || !user_access('pm')) {
    return;
  }

  //$translation_edit_link = l(lingotek_language_field_lookup('native', $lingotek_locale), '', array('attributes' => array('onclick' => 'window.open(\'' . lingotek_get_workbench_url($node, $lingotek_locale) . '\'); return false;')));
  $node = lingotek_empty_node();
  $document_id = FALSE;
  if (isset($form['nid']['#value'])) {
    $nid = $form['nid']['#value'];
    $node = node_load($nid);
    $document_id = lingotek_lingonode($nid, 'document_id');
  }
  global $language;
  $drupal_language_code = $language->language;
  if ($drupal_language_code != $node->language && lingotek_node_pushed($node)) {
    $lingotek_locale = Lingotek::convertDrupal2Lingotek($drupal_language_code);
    lingotek_set_target_sync_status($node->nid, $lingotek_locale, LINGOTEK_TARGET_SYNC_STATUS_PENDING);

    //set to pending so any changes will be downloaded on next sync
    $language_text = lingotek_language_field_lookup('native', $lingotek_locale) . " (" . $drupal_language_code . ")";
    $translation_edit_link = lingotek_get_workbench_url($node, $lingotek_locale, t('Edit Translation: @language_text ', array(
      '@language_text' => $language_text,
    )));
    $edit_translation_message = t('Editing the fields below will only change the content of the source language, not the translation.');
    $edit_translation_message .= "<br/>" . $translation_edit_link;
    drupal_set_message($edit_translation_message, 'warning', FALSE);
  }
  if (LingotekAccount::instance()
    ->isEnterprise() === FALSE) {
    return;

    // Only enterprise users need to see this screen.
  }
  drupal_add_css(drupal_get_path('module', 'lingotek') . '/style/form.css');

  //$options = array();

  //$options[TRUE] = t('Enabled');

  //$options[FALSE] = t('Disabled');
  $title = t('Translation Management');

  // Vertical Tab.
  $form['lingotek'] = array(
    '#title' => t('Translation Mangement'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'id' => array(
        'lingotek_fieldset',
      ),
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'lingotek') . '/js/lingotek.form.js',
      ),
    ),
  );
  $form['lingotek']['et_content'] = array(
    '#type' => 'container',
  );
  $form['lingotek']['et_content']['explanation'] = array(
    '#title' => $title,
    '#type' => 'item',
    '#description' => t('Translation of this node is currently managed by the Entity Translation module. Click the "Enable Lingotek" button to begin using the Lingotek module to manage this node\'s translation.  Upon saving the node, its content will be uploaded to Lingotek.  You will not be able to switch back to using Entity Translation for this node.'),
  );
  $form['lingotek']['et_content']['is_et_node'] = array(
    '#type' => 'hidden',
    '#value' => lingotek_managed_by_entity_translation($form['#node']->type),
    '#attributes' => array(
      'id' => 'ltk-entity-translation-node',
    ),
  );
  $form['lingotek']['lingotek_push_once'] = array(
    '#type' => 'checkbox',
    '#default_value' => 0,
    '#attributes' => array(
      'id' => 'ltk-push-once',
      'style' => 'display: none',
    ),
  );
  $form['lingotek']['et_content']['btn'] = array(
    '#type' => 'button',
    '#value' => 'Enable Lingotek',
    '#attributes' => array(
      'id' => 'ltk-enable-from-et',
      'onclick' => 'return false;',
    ),
  );
  $form['lingotek']['note'] = array(
    '#type' => 'item',
    '#title' => $title,
    '#description' => t('Please select a language for Lingotek to use as the source language.  The source language cannot be language neutral.'),
  );
  $form['lingotek']['content'] = array(
    '#type' => 'container',
  );
  $form['lingotek']['content']['note'] = array(
    '#type' => 'item',
    '#title' => $title,
    '#description' => t("The Lingotek module was developed to aid you in getting your Drupal site translated. The module integrates the Lingotek translation management system directly into Drupal, so that your users can leverage the power of Lingotek's translation tools and services without ever having to leave the comfort of your Drupal environment."),
  );
  $form['lingotek']['content']['create_lingotek_document'] = array(
    '#type' => 'checkbox',
    '#title' => t('Upload Content Automatically'),
    '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'create_lingotek_document'), 'lingotek_create_documents_by_default', 0),
    '#description' => t('When enabled, your Drupal content (including saved edits) will automatically be uploaded to Lingotek for translation.<br/>When disabled, you are required to manually upload your content by clicking the "Upload" button on the Lingteok tab.'),
  );
  $form['lingotek']['content']['syncMethod'] = array(
    '#type' => 'checkbox',
    '#title' => t('Download Translations Automatically'),
    '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'sync_method'), 'lingotek_sync', 1),
    '#access' => user_access('sync_method'),
    '#description' => t('When enabled, completed translatoins will automatically be downloaded from Lingotek.<br/>When disabled, you are required to manually download translations by clicking the "Download" button on the Lingotek tab.'),
  );

  // Paste Source Setting.

  /* $form['lingotek']['content']['useSource'] = array(
     '#type' => 'select',
     '#title' => t('Include source text in synchronization.'),
     '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'use_source'), 'lingotek_use_source', TRUE),
     '#options' => $options,
     '#access' => user_access('use_source'),
     '#description' => t("This determines if the target languages will fill untranslated text with the source language or simply leave untranslated text out of the document."),
     ); */

  // Community Translation
  $form['lingotek']['content']['lingotek_allow_community_translation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow Community Translation'),
    '#description' => t('When enabled, anonymous site visitors will be presented with a link allowing them to contribute translations for this node.'),
    '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'allow_community_translation'), 'lingotek_allow_community_translation', 0),
  );

  // URL Alias Translation.
  if (user_access('url_alias_translation')) {
    $form['lingotek']['content']['urlAliasTranslation'] = array(
      '#type' => 'select',
      '#title' => t('URL Alias Translation'),
      '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'url_alias_translation'), 'lingotek_url_alias_translation', 1),
      '#options' => lingotek_get_url_alias_translations(),
      '#description' => t('Choose how you would like to translate the URL alias. The last option requires that you install both the Title and Pathauto modules, define a path pattern, and check "Enable Lingotek Translation" for the Title field.'),
    );
  }

  // Only show these options if the Lingotek document hasn't yet been created.
  if (!$document_id && class_exists('LingotekApi')) {
    $api = LingotekApi::instance();

    // Available projects.
    if ($projects = $api
      ->listProjects()) {
      $form['lingotek']['content']['lingotek_project_id'] = array(
        '#type' => 'select',
        '#title' => 'Project',
        '#description' => t('Select the translation project with which this item should be associated.'),
        '#default_value' => variable_get('lingotek_project', ''),
        '#options' => $projects,
        '#access' => user_access('access per-item lingotek project selection'),
      );
    }

    // Workflows.
    if ($workflows = $api
      ->listWorkflows()) {
      $form['lingotek']['content']['lingotek_workflow_id'] = array(
        '#type' => 'select',
        '#title' => t('Workflow'),
        '#description' => t('Choose the Workflow to associate with this content item.'),
        '#default_value' => variable_get('lingotek_workflow', ''),
        '#options' => $workflows,
        '#access' => user_access('access per-item lingotek project selection'),
      );
    }

    // Translation Memory (TM) Vault.
    if ($vaults = $api
      ->listVaults()) {
      $form['lingotek']['content']['lingotek_vault_id'] = array(
        '#type' => 'select',
        '#title' => t('TM Vault'),
        '#description' => t('Choose the TM vault to associate with this content item.'),
        '#default_value' => variable_get('lingotek_vault', ''),
        '#options' => $vaults,
        '#access' => user_access('access per-item lingotek vault selection'),
      );
    }
  }

  // END:  Document not created yet
  $form['lingotek']['developer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Developer Settings (Advanced)'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'developer_settings',
    '#access' => user_access('dev'),
  );
  if ($document_id === False) {
    $document_id = '';
  }
  $form['lingotek']['developer']['document_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Document Id'),
    '#description' => t("Read/Overwrite the document ID associated with the document.  This can break the translation process but can also be used to help figure out if something is wrong."),
    '#default_value' => $document_id,
  );
  $values = t('None');
  if (isset($nid)) {
    $values = json_encode(lingotek_lingonode($nid));
  }
  $form['lingotek']['developer']['current_lingonode'] = array(
    '#type' => 'item',
    '#title' => t('Node Variables'),
    '#description' => check_plain($values),
  );
}