You are here

function lingotek_admin_profile_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_profile_form()
  2. 7.4 lingotek.admin.inc \lingotek_admin_profile_form()
  3. 7.5 lingotek.admin.inc \lingotek_admin_profile_form()

Content defaults Form

1 call to lingotek_admin_profile_form()
lingotek_setup_node_translation_settings_form in ./lingotek.setup.inc
Entity Translation Settings - Form Layout Select the Content Types and Fields to be Translated.
1 string reference to 'lingotek_admin_profile_form'
lingotek_admin_profile_manage in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 1687

Code

function lingotek_admin_profile_form($form, &$form_state, $show_fieldset = FALSE) {
  $account = LingotekAccount::instance();
  $api = LingotekApi::instance();
  $site = variable_get('site_name', 'Drupal Site');
  $profile_id = isset($form_state['values']['profile_id']) ? $form_state['values']['profile_id'] : -1;
  $stored_profile = lingotek_get_profile_settings($profile_id);
  $first_custom_id = 2;
  $is_custom_profile_id = $profile_id >= $first_custom_id;
  $show_advanced = $account
    ->showAdvanced();

  //$form['#action'] = url('admin/settings/lingotek/settings', array('fragment' => 'ltk-profiles'));
  $form['defaults']['profile_id'] = array(
    '#type' => 'value',
    '#value' => $form_state['values']['profile_id'],
  );
  $form['defaults']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile Name'),
    '#default_value' => $form_state['values']['name'],
    '#disabled' => $is_custom_profile_id ? FALSE : TRUE,
  );
  $form['defaults']['current_future_note'] = array(
    '#type' => 'markup',
    '#markup' => '<h3>' . t('Profile settings impacting all entities (new and existing)') . '</h3><hr />',
  );

  // Upload
  $form['defaults']['create_lingotek_document'] = array(
    '#type' => 'checkbox',
    '#title' => t('Upload Content Automatically'),
    '#default_value' => $form_state['values']['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.'),
    '#disabled' => $is_custom_profile_id ? FALSE : TRUE,
  );

  // Download
  $form['defaults']['sync_method'] = array(
    '#type' => 'checkbox',
    '#title' => t('Download Translations Automatically'),
    '#default_value' => $form_state['values']['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.'),
    '#disabled' => $is_custom_profile_id ? FALSE : TRUE,
  );

  // URL Alias Translation.
  $form['defaults']['url_alias_translation'] = array(
    '#type' => 'select',
    '#title' => t('URL Alias Translation'),
    '#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."),
    '#options' => lingotek_get_url_alias_translations(),
    '#default_value' => $form_state['values']['url_alias_translation'],
  );
  if ($show_advanced) {

    /* OPTIONS REMOVED UNTIL FEATURE IS IMPLEMENTED
       // Target Localization
       $form['defaults']['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' => $form_state['values']['allow_target_localization'],
       );
       // Source Overwriting
       $form['defaults']['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' => $form_state['values']['allow_source_overwriting'],
       );
       */

    // Community Translation
    $form['defaults']['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' => $form_state['values']['allow_community_translation'],
    );
  }

  // Workflows
  $workflows = $api
    ->listWorkflows();
  if ($workflows && count($workflows) > 1) {
    $stored_workflow_id = isset($stored_profile['workflow_id']) ? $stored_profile['workflow_id'] : '';
    $selected_workflow_id = isset($form_state['values']['workflow_id']) ? $form_state['values']['workflow_id'] : $stored_workflow_id;
    $curr_workflow = $api
      ->getWorkflow($stored_workflow_id);
    if (!empty($curr_workflow)) {

      // append the current workflow to the top of the workflow list, if it's not already there
      $workflows = array(
        $stored_workflow_id => $curr_workflow->name,
      ) + $workflows;
    }
    $form['defaults']['workflow_id'] = array(
      '#type' => 'select',
      '#title' => t('Default Workflow'),
      '#description' => t('The default Workflow to use when translating content.'),
      '#default_value' => $stored_workflow_id,
      '#options' => $workflows,
      '#ajax' => array(
        'callback' => 'lingotek_profile_default_workflow_form_callback',
        'wrapper' => 'prefill-phases-div',
        'method' => 'replace',
        'effect' => 'fade',
      ),
      '#prefix' => '<div id="prefill-phases-div">',
    );
    $form['defaults']['prefill_phases_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => t('Change all current content in this profile (@total in total) to use the new workflow', array(
        '@total' => array_sum(lingotek_admin_profile_usage($profile_id)),
      )),
      '#default_value' => FALSE,
      '#description' => t('All current translations will be removed and recreated using the new workflow, with translations pulled from the previous workflow'),
      '#states' => array(
        'invisible' => array(
          ':input[name="workflow_id"]' => array(
            'value' => $stored_workflow_id,
          ),
        ),
      ),
    );
    $form['defaults']['prefill_phase_select'] = array(
      '#title' => t("Desired Prefill Phase"),
      '#description' => t('Please select the highest phase which should be prefilled for the new workflow'),
      '#type' => 'select',
      '#states' => array(
        'visible' => array(
          ':input[name="workflow_id"]' => array(
            '!value' => $stored_workflow_id,
          ),
          ':input[name="prefill_phases_checkbox"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#suffix' => '</div>',
    );
    $form['defaults']['prefill_phase_select']['#options'] = lingotek_get_phases_by_workflow_id($selected_workflow_id);
  }

  // FUTURE-ONLY STUFF
  $form['defaults']['future_only_note'] = array(
    '#type' => 'markup',
    '#markup' => '<h3>' . t('Profile settings impacting only new nodes') . '</h3><hr />',
  );
  $content_translation_note = '';
  if (!lingotek_node_based_trans_ready()) {
    $content_translation_note = t("This method requires Content Translation module (translation) and Multilingual content module (i18n_node).");
  }
  $form['defaults']['lingotek_nodes_translation_method'] = array(
    '#type' => 'radios',
    '#title' => t('Translation Storage'),
    '#options' => array(
      'field' => t('<strong>Field Translation</strong> (Recommended) - all translations are stored in a single node'),
      'node' => t('<strong>Node Translation</strong>  - create a new node per language'),
    ),
    'field' => array(
      '#description' => t('A newer and recommended method. Newer versions of Drupal are expected to use this method.  (Note: If this method is selected, all fields chosen for Lingotek translation (below) will be marked as translatable in the Drupal field configuration.)'),
    ),
    'node' => array(
      '#description' => t('The classical method. Use for backwards compatibility.  (Note: If this method is selected, fields chosen for Lingotek translation will *not* be marked as translatable in the Drupal field configuration.  Instead, translations will be saved as language-neutral, allowing the node to dictate the language.  This method will not work for translating other entity types, such as taxonomy terms and messages.  <i>@note</i>)', array(
        '@note' => $content_translation_note,
      )),
    ),
    '#default_value' => isset($form_state['values']['lingotek_nodes_translation_method']) ? $form_state['values']['lingotek_nodes_translation_method'] : 'field',
    '#disabled' => lingotek_node_based_trans_ready() ? FALSE : TRUE,
  );

  // Projects
  $projects = class_exists('LingotekApi') ? $api
    ->listProjects() : array();
  $id = variable_get('lingotek_project', '');
  if ($id == '' || !array_key_exists($id, $projects)) {

    //No project id set, project deleted, or community changed to one without that project.  Try to find the Drupal project
    $id = array_search($site, $projects);
    if ($id === False) {

      //Setup a default Drupal project
      $id = lingotek_add_project($site);
      $projects = class_exists('LingotekApi') ? $api
        ->listProjects() : array();
    }
    else {

      //Assign to an existing Drupal project
      variable_set('lingotek_project', $id);
    }
  }
  if ($projects && count($projects) > 1) {
    $sorted = asort($projects);
    $form['defaults']['project_id'] = array(
      '#type' => 'select',
      '#title' => t('Default Project'),
      '#options' => $projects,
      '#description' => t('The default Lingotek Project with which translations will be associated.'),
      '#default_value' => isset($form_state['values']['project_id']) ? $form_state['values']['project_id'] : $id,
    );
  }
  $vaults = $api
    ->listVaults();
  $current_vault_id = variable_get('lingotek_vault', '');
  $personal_vault_count = isset($vaults['Personal Vaults']) ? count($vaults['Personal Vaults']) : 0;
  $community_vault_count = isset($vaults['Community Vaults']) ? count($vaults['Community Vaults']) : 0;

  // If no vault id is set, and we don't have any personal vaults, then create one and add it to our project.
  if ($current_vault_id == '' && $personal_vault_count == 0 && $community_vault_count == 0) {
    $current_project_id = variable_get('lingotek_project', '');

    // But only if we have a ProjectID.
    if ($current_project_id != '') {
      $current_vault_id = lingotek_add_vault($site);
      lingotek_add_vault_to_project();
    }
  }
  if ($personal_vault_count + $community_vault_count > 1) {
    $form['defaults']['vault_id'] = array(
      '#type' => 'select',
      '#title' => t('Default Vault'),
      '#options' => $vaults,
      '#description' => t('The default Translation Memory Vault where translations are saved.'),
      '#default_value' => isset($form_state['values']['vault_id']) ? $form_state['values']['vault_id'] : $current_vault_id,
    );
  }
  $form['defaults']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  // if no entities or bundles are assigned to the profile, and if it was created
  // by the site admin, then allow deletion.
  if (array_sum(lingotek_admin_profile_usage($profile_id)) == 0 && lingotek_admin_profile_usage_by_types($profile_id) == 0 && $is_custom_profile_id) {
    $form['defaults']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  else {
    $markup = $is_custom_profile_id ? t('You can only delete this profile when there are no entities or bundles using it.') : t('This profile cannot be deleted.');
    $form['delete'] = array(
      '#markup' => '<span class="ltk-muted" style="font-style: italic;">' . $markup . '</span>',
    );
  }
  $form['defaults']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  return $form;
}