You are here

function lingotek_form_node_form_alter in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lingotek.module \lingotek_form_node_form_alter()
  2. 7.2 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 474

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('manage projects')) {
    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 = lingotek_node_load_default($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);
    LingotekSync::setTargetStatus($node->nid, $lingotek_locale, LingotekSync::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);
  }
  $is_enterprise = LingotekAccount::instance()
    ->isEnterprise();
  $workbench_moderation_enabled = FALSE;
  if (module_exists('workbench_moderation')) {
    $workbench_moderation_enabled = TRUE;
  }
  drupal_add_css(drupal_get_path('module', 'lingotek') . '/style/form.css');
  $title = t('Translation Management');

  // Vertical Tab.
  $form['lingotek'] = array(
    '#title' => t('Translation management'),
    '#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 Translation 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 Translation module was developed to help you tranlate your site. 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 Translations tab.'),
  );
  if ($workbench_moderation_enabled && workbench_moderation_node_type_moderated($form['type']['#value'])) {
    $form['lingotek']['content']['create_lingotek_document_workbench_moderation'] = array(
      '#type' => 'select',
      '#title' => t('Workbench Moderation Upload'),
      '#field_prefix' => t('Upload to Lingotek when node reaches'),
      '#field_suffix' => t('state.'),
      '#options' => lingotek_get_workbench_moderation_states(),
      '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'create_lingotek_document_workbench_moderation'), 'lingotek_create_documents_by_default_workbench_moderation', workbench_moderation_state_published()),
      '#description' => 'The most recent revision will be automatically uploaded when changed to this state.',
      '#states' => array(
        'invisible' => array(
          ':input[name="create_lingotek_document"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
  }
  $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('adjust auto-download node setting'),
    '#description' => t('When enabled, completed translations will automatically be downloaded from Lingotek.<br/>When disabled, you are required to manually download translations by clicking the "Download" button on the Translations tab.'),
  );
  if ($workbench_moderation_enabled && workbench_moderation_node_type_moderated($form['type']['#value'])) {
    $transition_select = lingotek_workbench_moderation_get_mult_transitions();
    $form['lingotek']['content']['syncMethod_wb'] = array(
      '#type' => 'select',
      '#title' => t('Workbench Moderation Download'),
      '#field_suffix' => t('after translations have downloaded from Lingotek.'),
      '#options' => lingotek_get_workbench_moderation_options(),
      '#default_value' => lingotek_variable_get(lingotek_lingonode($node->nid, 'sync_method_workbench_moderation'), 'lingotek_sync_workbench_moderation', 'no_moderation'),
      '#description' => t("Transition will not occur until <i>all</i> of the node's translations have downloaded."),
      '#states' => array(
        'invisible' => array(
          ':input[name="syncMethod"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
  }
  if ($is_enterprise) {

    // 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('translate url aliases')) {
      $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']['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'developer_settings',
    '#access' => user_access('use lingotek developer tools'),
  );
  $form['lingotek']['advanced']['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 === False ? '' : $document_id,
  );
  $form['lingotek']['advanced']['current_lingonode'] = array(
    '#type' => 'textarea',
    '#title' => t('Node Data'),
    '#value' => isset($nid) ? json_encode(lingotek_lingonode($nid)) : t('None'),
    '#disabled' => TRUE,
    '#attributes' => array(
      'rows' => '2',
    ),
  );
}