You are here

function lingotek_get_node_settings_form in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lingotek.module \lingotek_get_node_settings_form()
  2. 7.5 lingotek.module \lingotek_get_node_settings_form()
  3. 7.6 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 878

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/lingotek.form.css');
  $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,
      )),
    );
    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. If changing to a profile with additional target languages, those languages will be added locally and in the TMS. If changing to a profile without all current target languages then the default setting is to leave the target language in the TMS but not locally; this can be changed in the Lingotek Preferences. To change the workflow, however, you must use the Change Workflow 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;
  }

  // Don't mess with the profile of an existing node (only the new ones).
  $form['preserve_profile'] = array(
    '#type' => 'hidden',
    '#value' => isset($node->nid) ? 1 : 0,
    '#attributes' => array(
      'id' => 'lingotek-preserve-profile',
    ),
  );
  $form['lingotek']['profile'] = array(
    '#type' => 'select',
    '#title' => t('Translation Profile'),
    '#options' => lingotek_get_profile_options(),
  );
  if (!$bulk_grid) {

    // Set the initial profile default.
    $bundle_profile = LingotekProfile::loadByBundle($entity_type, $form['#bundle']);
    $form['lingotek']['profile']['#default_value'] = isset($node->lingotek['profile']) ? $node->lingotek['profile'] : $bundle_profile
      ->getId();

    // Do some js handling of profile changes
    $entity_profiles = variable_get('lingotek_entity_profiles', array());
    $node_profiles = $entity_profiles['node'];
    $bundle_profiles_by_langcode = lingotek_filter_profiles_by_bundle_and_langcode($form['type']['#value'], $node_profiles);
    global $language;
    $form['lingotek']['system_default'] = array(
      '#type' => 'hidden',
      '#value' => $language->language,
      '#attributes' => array(
        'id' => 'lingotek-system-default',
      ),
    );
    $form['lingotek']['bundle_profiles'] = array(
      '#type' => 'hidden',
      '#value' => json_encode($bundle_profiles_by_langcode),
      '#attributes' => array(
        'id' => 'lingotek-bundle-profiles',
      ),
    );
    $form['lingotek']['language_specific_profiles'] = array(
      '#type' => 'hidden',
      '#value' => variable_get('lingotek_enable_language_specific_profiles', '0'),
      '#attributes' => array(
        'id' => 'lingotek-language-specific-profiles',
      ),
    );
  }

  // 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' => !empty($node->lingotek['document_id']) ? $node->lingotek['document_id'] : '',
  );
  $form['lingotek']['upload_status'] = array(
    '#type' => 'value',
    '#value' => !empty($node->lingotek['upload_status']) ? $node->lingotek['upload_status'] : '',
  );
  if ($bulk_grid) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#submit' => array(
        'lingotek_get_node_settings_form_submit',
      ),
    );
  }

  // include additional form components
  if (!variable_get('lingotek_advanced_menu_links', FALSE)) {
    $form = lingotek_add_menu_link_form($form, $form_state, $node);
  }
  return $form;
}