You are here

function lingotek_admin_profile_form in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lingotek.admin.inc \lingotek_admin_profile_form()
  2. 7.5 lingotek.admin.inc \lingotek_admin_profile_form()
  3. 7.6 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 1881

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 = LingotekProfile::loadById($profile_id);
  $first_custom_id = 2;
  $is_custom_profile_id = $profile_id >= $first_custom_id;
  $show_advanced = $account
    ->showAdvanced();
  $download_translations_title = t('Download Translations Automatically');
  $download_translations_desc = 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.');

  //$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,
    '#required' => 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']['auto_upload'] = array(
    '#type' => 'checkbox',
    '#title' => t('Upload Content Automatically'),
    '#default_value' => $form_state['values']['auto_upload'],
    '#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']['auto_download'] = array(
    '#type' => 'checkbox',
    '#title' => filter_xss($download_translations_title),
    '#default_value' => $form_state['values']['auto_download'],
    '#description' => filter_xss($download_translations_desc),
    '#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 (!empty($workflows) && count($workflows) > 1) {
    $stored_workflow_id = $stored_profile
      ->getWorkflow();
    $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() : FALSE;
  $id = variable_get('lingotek_project', '');

  // If it is not an array, it means that the API failed, so we will not auto provision a project for them.
  if (is_array($projects) && count($projects) == 0 && $id == '') {

    // No project id set, project deleted, or community changed to one without that project.  Try to find the Drupal project

    //Setup a default Drupal project
    $id = lingotek_add_project($site);
    $projects = class_exists('LingotekApi') ? $api
      ->listProjects() : FALSE;
  }
  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,
    );
  }

  // TARGET-LANGUAGE OVERRIDES
  if (variable_get('lingotek_enable_language_specific_profiles', FALSE)) {
    $form['defaults']['language_overrides_label'] = array(
      '#type' => 'markup',
      '#markup' => '<h3>' . t('Target Languages') . '</h3><hr />',
    );
    $languages = lingotek_get_target_locales(FALSE);
    usort($languages, "lingotek_language_specific_profile_cmp");
    $form['defaults']['language_overrides'] = array();
    $settings_options = array(
      LingotekSync::PROFILE_INHERIT => 'Inherit default settings',
      LingotekSync::PROFILE_CUSTOM => 'Use custom settings',
      LingotekSync::PROFILE_DISABLED => 'Disabled',
    );
    foreach ($languages as $language) {
      if ($stored_profile
        ->isTargetLocaleDisabled($language->lingotek_locale)) {
        $default_language_override_value = LingotekSync::PROFILE_DISABLED;
      }
      elseif ($stored_profile
        ->isTargetLocaleCustom($language->lingotek_locale)) {
        $default_language_override_value = LingotekSync::PROFILE_CUSTOM;
      }
      else {
        $default_language_override_value = LingotekSync::PROFILE_INHERIT;
      }
      $title_message = $language->name . ' (' . $default_language_override_value . ')';
      $form['defaults']['language_override'][$language->lingotek_locale] = array(
        '#title' => filter_xss($title_message),
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#id' => 'language_override__' . $language->lingotek_locale,
      );
      $form['defaults']['language_override'][$language->lingotek_locale]['settings_' . $language->lingotek_locale] = array(
        '#type' => 'select',
        '#options' => $settings_options,
        '#default_value' => $default_language_override_value,
      );
      $is_automatic_or_manual_profile = in_array($stored_profile
        ->getId(), array(
        LingotekSync::PROFILE_AUTOMATIC,
        LingotekSync::PROFILE_MANUAL,
      ));
      $auto_download = $stored_profile
        ->isAutoDownload($language->lingotek_locale);
      $form['defaults']['language_override'][$language->lingotek_locale]['auto_download_' . $language->lingotek_locale] = array(
        '#type' => 'checkbox',
        '#title' => filter_xss($download_translations_title),
        '#default_value' => $auto_download,
        '#disabled' => $is_automatic_or_manual_profile,
        '#states' => array(
          'invisible' => array(
            ':input[name="settings_' . $language->lingotek_locale . '"]' => array(
              '!value' => LingotekSync::PROFILE_CUSTOM,
            ),
          ),
        ),
      );
      if ($is_automatic_or_manual_profile) {
        $form['defaults']['language_override'][$language->lingotek_locale]['auto_download_' . $language->lingotek_locale]['#description'] = t('(disabled because this profile is @profile_name)', array(
          '@profile_name' => $stored_profile
            ->getName(),
        ));
      }
      if (!empty($workflows) && count($workflows) > 1) {
        $curr_workflow = $stored_profile
          ->getWorkflow($language->lingotek_locale);
        $form['defaults']['language_override'][$language->lingotek_locale]['workflow_id_' . $language->lingotek_locale] = array(
          '#type' => 'select',
          '#title' => t('Workflow'),
          '#options' => $workflows,
          '#default_value' => $curr_workflow ? $curr_workflow : $stored_workflow_id,
          '#empty_option' => '(select one)',
          '#states' => array(
            'invisible' => array(
              ':input[name="settings_' . $language->lingotek_locale . '"]' => array(
                '!value' => LingotekSync::PROFILE_CUSTOM,
              ),
            ),
          ),
        );
      }
    }
  }
  $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; margin-right:10px;">' . $markup . '</span>',
    );
  }
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), '#', array(
      'attributes' => array(
        'class' => 'ctools-close-modal',
      ),
      'external' => TRUE,
    )),
  );
  return $form;
}