You are here

function lingotek_get_node_settings_form in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 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()
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 733

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;
  if (isset($form_state['nids'])) {
    $nids = $form_state['nids'];
    $bulk_grid = TRUE;
    $multiple = count($nids) > 1;
    if (!$multiple) {
      $node = lingotek_node_load_default(reset($nids));
    }
    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');
  $is_enterprise = LingotekAccount::instance()
    ->isEnterprise();
  $workbench_moderation_enabled = module_exists('workbench_moderation');
  $title = t('Translation Management');

  // Vertical Tab.
  $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 (isset($node->tnid) && $node->tnid != 0 && $node->tnid != $node->nid) {
    $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."),
  );
  $profiles = lingotek_get_profiles();
  $profile_options = array();
  foreach ($profiles as $key => $profile) {
    $profile_options[$key] = $profile['name'];
  }
  $profile_options[LingotekSync::PROFILE_CUSTOM] = 'Custom';
  $profile_options[LingotekSync::PROFILE_DISABLED] = 'Disabled';
  $form['lingotek']['profile'] = array(
    '#type' => 'select',
    '#title' => 'Translation Profile',
    '#options' => $profile_options,
    '#default_value' => $node->lingotek['profile'],
  );
  if ($node->lingotek['node_sync_status'] == LingotekSync::STATUS_DISABLED) {
    $form['lingotek']['profile']['#default_value'] = LingotekSync::PROFILE_DISABLED;
  }
  $form['lingotek']['node_sync_status'] = array(
    '#type' => 'value',
    '#value' => $node->lingotek['node_sync_status'],
  );
  $form['lingotek']['content_begin'] = array(
    '#markup' => '<div id="edit-lingotek-content" class="form-wrapper">',
  );
  if (!$bulk_grid) {
    $form['lingotek']['lingotek_nodes_translation_method'] = array(
      '#type' => 'radios',
      '#title' => t('Method for storing translations'),
      '#options' => array(
        'field' => '<strong>Fields</strong> (Recommended) - all translations are stored in a single node',
        'node' => '<strong>Nodes</strong>  - create a new node per language ',
      ),
      'field' => array(
        '#description' => 'A newer and recommended method. It appears newer versions of Drupal will use this method.',
      ),
      'node' => array(
        '#description' => 'The classical method. Use for backwards compatibility.',
      ),
      '#disabled' => isset($node->nid),
      '#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.'),
  );
  $show_moderation = FALSE;
  if ($workbench_moderation_enabled) {

    /*foreach ($nodes as $node) {
        $show_moderation = workbench_moderation_node_type_moderated($node->type);
        if ($show_moderation) {
        break;
        }
      }*/
    $show_moderation = $bulk_grid || workbench_moderation_node_type_moderated($node->type);
    if ($show_moderation) {
      $form['lingotek']['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' => $multiple ? workbench_moderation_state_published() : $node->lingotek['create_lingotek_document_workbench_moderation'],
        '#description' => 'The most recent revision will be automatically uploaded when changed to this state.',
        '#states' => array(
          'invisible' => array(
            ':input[id="edit-lingotek-create-lingotek-document"]' => array(
              'checked' => FALSE,
            ),
          ),
        ),
      );
    }
  }
  $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.'),
  );
  if ($workbench_moderation_enabled) {
    $default_download_state = 'no_moderation';
    if (!$multiple && isset($node->nid)) {
      $default_download_state = $node->lingotek['sync_method_workbench_moderation'];
    }
    if ($show_moderation) {
      $transition_select = lingotek_workbench_moderation_get_mult_transitions();
      $form['lingotek']['sync_method_workbench_moderation'] = 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' => $default_download_state,
        '#description' => t("Transition will not occur until <i>all</i> of the node's translations have downloaded."),
        '#states' => array(
          'invisible' => array(
            ':input[id="edit-lingotek-syncmethod"]' => array(
              'checked' => FALSE,
            ),
          ),
        ),
      );
    }
  }
  if ($is_enterprise) {

    // 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'],
    );

    // 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, define a path pattern, and check "Enable Lingotek Translation" for the Title field.'),
    );
  }
  if ($bulk_grid) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#submit' => array(
        'lingotek_get_node_settings_form_submit',
      ),
    );
  }
  return $form;
}