You are here

function lingotek_get_node_settings_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.module \lingotek_get_node_settings_form()
  2. 7.4 lingotek.module \lingotek_get_node_settings_form()
  3. 7.5 lingotek.module \lingotek_get_node_settings_form()

Display the Lingotek node-settings form

This form is used both in a tab at the bottom of each node's edit form (Translation management) and in the bulk-action select box on the translation manage page (Edit Translation Settings).

Parameters

array $form: the passed form elements

array $form_state: the form state, including submitted values if any

object $node: an optional node on which to act

Return value

array the modified form

1 call to lingotek_get_node_settings_form()
lingotek_form_node_form_alter in ./lingotek.module
Implements hook_form_BASE_FORM_ID_alter().
1 string reference to 'lingotek_get_node_settings_form'
lingotek_edit_nodes in ./lingotek.bulk_grid.inc
Callback function to edit settings for multiple nodes at a time

File

./lingotek.module, line 809

Code

function lingotek_get_node_settings_form($form, &$form_state, $node = NULL) {
  $second_run = isset($form_state['input']['op']);
  $bulk_grid = FALSE;
  $multiple = FALSE;

  //$new_node = isset($node->nid) ? 0 : 1;
  $entity_type = isset($form_state['entity_type']) ? $form_state['entity_type'] : 'node';
  if (isset($form_state['nids'])) {
    $nids = $form_state['nids'];
    $bulk_grid = TRUE;
    $multiple = count($nids) > 1;
    if (!$multiple) {
      $node = lingotek_entity_load_single($entity_type, $nids[0]);
    }
    else {
      if (!$second_run) {
        drupal_set_message(t('You will be changing the settings for @number nodes.', array(
          '@number' => count($nids),
        )), 'warning');
      }
      $node = new stdClass();
      $node->lingotek = lingotek_get_global_profile();
      $node->lingotek['profile'] = LingotekSync::PROFILE_DISABLED;

      // Note: Consider making this default 'Automatic' (after it is a fixed profile; can't be deleted)
    }
  }
  drupal_add_css(drupal_get_path('module', 'lingotek') . '/style/form.css');
  $show_advanced = LingotekAccount::instance()
    ->showAdvanced();
  $enabled_languages = lingotek_get_target_locales(TRUE);
  $node_language = Lingotek::convertDrupal2Lingotek($node->language);

  // Vertical Tab.
  // (When the Lingotek module is enabled, then show the translation tab unless
  // the node is *not* managed by Lingotek or the language is *not* managed by
  // Lingotek, *and* it is a node-based translation of a different (source) node.
  if (lingotek_is_node_translation($node)) {
    if (isset($node->translation_source->lingotek['profile']) && $node->translation_source->lingotek['profile'] === LingotekSync::PROFILE_DISABLED) {
      return $form;
    }
    if (!in_array($node_language, $enabled_languages)) {
      return $form;
    }
  }
  $title = t('Translation Management');
  $form['lingotek'] = array(
    '#title' => t('Translation management'),
    '#type' => 'fieldset',
    '#collapsible' => !$bulk_grid,
    '#collapsed' => !$bulk_grid,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'id' => array(
        'lingotek_fieldset',
      ),
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'lingotek') . '/js/lingotek.form.js',
      ),
    ),
    '#modal' => TRUE,
    '#tree' => TRUE,
  );
  if (lingotek_is_node_translation($node) && in_array($node_language, $enabled_languages)) {
    $form['lingotek']['note'] = array(
      '#markup' => t('This is a target node for the language code: @lang. To change
        the Lingotek settings please edit the source node.', array(
        '@lang' => $node->language,
      )),
    );
    $form['lingotek']['content_begin'] = array(
      '#markup' => '<div id="edit-lingotek-content" class="form-wrapper">',
    );
    return $form;

    //this is a target node and thus should not have lingotek settings
  }
  if (isset($nids)) {
    $form['lingotek']['nids'] = array(
      '#type' => 'hidden',
      '#default_value' => json_encode($nids),
    );
  }
  if (!$bulk_grid) {

    // $node will be set because $multiple has to be 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.'),
    );
  }

  // END: Entity Translation Settings
  $form['lingotek']['lingotek_note'] = array(
    '#type' => 'item',
    '#title' => $title,
    '#description' => t("The Lingotek Translation module was developed to help you translate 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."),
  );
  if (!empty($node->lingotek['document_id'])) {
    $form['lingotek']['lingotek_note']['#description'] .= t('<p><b>NOTE: This node has already been uploaded to Lingotek. To change the workflow, you must use the <i>Change Workflow</i> action on the Manage tab rather than modifying the Translation Profile here.</b></p>');
  }

  // With the Translation Management tab in place, disable it and return the
  // form if Lingotek hasn't been set up yet.
  if (!lingotek_is_module_setup(FALSE)) {
    $lingotek_setup_link = l(t('set up the module'), 'admin/settings/lingotek');
    $setup_description = t("To begin Lingotek Translation, please !set_up_the_module.", array(
      '!set_up_the_module' => $lingotek_setup_link,
    ));
    $form['lingotek']['lingotek_setup_note'] = array(
      '#type' => 'item',
      '#description' => filter_xss($setup_description),
    );
    return $form;
  }
  $form['lingotek']['profile'] = array(
    '#type' => 'select',
    '#title' => t('Translation Profile'),
    '#options' => lingotek_get_profile_options(),
    '#default_value' => $node->lingotek['profile'],
  );

  // Warning note when enabling nodes with existing Lingotek translations
  $overwrite_markup = '<div id="edit-lingotek-overwrite-warning"></div>';
  if (isset($nids) && lingotek_previously_managed_translations($entity_type, $nids)) {
    $overwrite_markup = '<div id="edit-lingotek-overwrite-warning" style="color: red;">Note: One or more of the entities selected have had previous Lingotek translations.  If edits have been made to the local copy of these translations since disabling Lingotek, those edits will be lost when synchronizing with Lingotek.</div>';
  }
  $form['lingotek']['overwrite_warning'] = array(
    '#markup' => $overwrite_markup,
  );
  $form['lingotek']['document_id'] = array(
    '#type' => 'value',
    '#value' => $node->lingotek['document_id'],
  );
  $form['lingotek']['upload_status'] = array(
    '#type' => 'value',
    '#value' => $node->lingotek['upload_status'],
  );
  $form['lingotek']['content_begin'] = array(
    '#markup' => '<div id="edit-lingotek-content" class="form-wrapper">',
  );
  $content_translation_note = '';
  if (!lingotek_node_based_trans_ready()) {
    $content_translation_note = t("Note: Requires Content Translation module (translation) and Multilingual content module (i18n_node).");
  }
  if (!$bulk_grid) {
    $form['lingotek']['lingotek_nodes_translation_method'] = array(
      '#type' => 'radios',
      '#title' => t('Method for storing translations'),
      '#options' => array(
        'field' => t('<strong>Fields</strong> (Recommended) - all translations are stored in a single node'),
        'node' => t('<strong>Nodes</strong>  - create a new node per language'),
      ),
      'field' => array(
        '#description' => t('A newer and recommended method. It appears newer versions of Drupal will use this method.'),
      ),
      'node' => array(
        '#description' => t('The classical method. Use for backwards compatibility. <i>@note</i>', array(
          '@note' => $content_translation_note,
        )),
      ),
      '#disabled' => isset($node->nid) || !lingotek_node_based_trans_ready(),
      '#default_value' => $node->lingotek['lingotek_nodes_translation_method'],
    );
  }
  $form['lingotek']['create_lingotek_document'] = array(
    '#type' => 'checkbox',
    '#title' => t('Upload Content Automatically'),
    '#default_value' => $node->lingotek['create_lingotek_document'],
    '#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.'),
  );
  $form['lingotek']['sync_method'] = array(
    '#type' => 'checkbox',
    '#title' => t('Download Translations Automatically'),
    '#default_value' => $node->lingotek['sync_method'],
    '#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.'),
  );

  // URL Alias Translation.
  $form['lingotek']['url_alias_translation'] = array(
    '#type' => 'select',
    '#title' => t('URL Alias Translation'),
    '#default_value' => $node->lingotek['url_alias_translation'],
    '#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, and define a path pattern.'),
  );
  if ($show_advanced) {

    /* REMOVED UNTIL FEATURE IS IMPLEMENTED
       // Target Localization
       $form['lingotek']['allow_target_localization'] = array(
         '#type' => 'checkbox',
         '#title' => t('Allow Target Localization'),
         '#description' => t('When enabled, localized target-language content can be created in Drupal and then uploaded for in-place translation.  Note: to prevent loss of the original localized content when using this option, you should have a versioning tool enabled for Drupal, such as Workbench Moderation.'),
         '#default_value' => $node->lingotek['allow_target_localization'],
       );
       // Source Overwriting
       $form['lingotek']['allow_source_overwriting'] = array(
         '#type' => 'checkbox',
         '#title' => t('Allow Source Overwriting'),
         '#description' => t('When enabled, source content may be created initially in a language other than the one set in Drupal and then translated in place of the original source content (ie. no separate target content will be created).  Note: to prevent the loss of the source content when using this option, you should have a versioning tool enabled for Drupal, such as Workbench Moderation.'),
         '#default_value' => $node->lingotek['allow_source_overwriting'],
       );
       */

    // Community Translation
    $form['lingotek']['allow_community_translation'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow Crowdsourced Translation'),
      '#description' => t('When enabled, anonymous site visitors will be presented with a link allowing them to contribute translations for this node.'),
      '#default_value' => $node->lingotek['allow_community_translation'],
    );
  }
  if ($bulk_grid) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#submit' => array(
        'lingotek_get_node_settings_form_submit',
      ),
    );
  }

  // include additional form components
  $form = lingotek_add_workflow_settings_form($form, $form_state, $node);
  $form = lingotek_add_advanced_form($form, $form_state, $node);
  $form = lingotek_add_menu_link_form($form, $form_state, $node);
  return $form;
}