You are here

function lingotek_admin_profile_form in Lingotek Translation 7.4

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

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');
  $is_enterprise = $account
    ->isEnterprise();
  $workbench_moderation_enabled = FALSE;
  if (module_exists('workbench_moderation')) {
    $workbench_moderation_enabled = TRUE;
  }
  $form['defaults']['profile_id'] = array(
    '#type' => 'value',
    '#value' => $form_state['values']['profile_id'],
  );
  $form['defaults']['name'] = array(
    '#type' => 'textfield',
    '#title' => 'Profile Name',
    '#default_value' => $form_state['values']['name'],
  );
  $form['defaults']['current_future_note'] = array(
    '#type' => 'markup',
    '#markup' => '<h3>' . t('Profile settings impacting all nodes (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'],
    //'#disabled' => !$is_enterprise,
    '#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.'),
  );
  if ($workbench_moderation_enabled) {
    $form['defaults']['create_lingotek_document_workbench_moderation'] = array(
      '#type' => 'select',
      '#title' => 'Workbench Moderation Uploads',
      '#options' => lingotek_get_workbench_moderation_states(),
      '#default_value' => isset($form_state['values']['create_lingotek_document_workbench_moderation']) ? $form_state['values']['create_lingotek_document_workbench_moderation'] : workbench_moderation_state_published(),
      '#states' => array(
        'invisible' => array(
          ':input[name="create_lingotek_document"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
      '#description' => 'The most recent revision will be automatically uploaded when changed to this state.',
    );
  }

  // 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.'),
  );
  if ($workbench_moderation_enabled) {
    $transition_select = lingotek_workbench_moderation_get_mult_transitions();
    $form['defaults']['lingotek_sync_wb']['sync_method_workbench_moderation'] = array(
      '#type' => 'select',
      '#title' => t('Workbench Moderation Downloads'),
      //      '#field_prefix' => t('After translations have downloaded'),
      '#field_suffix' => t('after translations have downloaded.'),
      '#options' => lingotek_get_workbench_moderation_options(),
      '#default_value' => isset($form_state['values']['sync_method_workbench_moderation']) ? $form_state['values']['sync_method_workbench_moderation'] : 'no_moderation',
      '#description' => t("Transitions will not occur until <i>all</i> of a node's translations have downloaded."),
      '#states' => array(
        'invisible' => array(
          ':input[name="sync_method"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
    if (!empty($transition_select)) {
      $form['defaults']['lingotek_sync_wb']['wb_select'] = array(
        '#type' => 'item',
        '#states' => array(
          'visible' => array(
            'select[name="sync_method_workbench_moderation"]' => array(
              'value' => 'increment',
            ),
            ':input[name="sync_method"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['defaults']['lingotek_sync_wb']['wb_select']['helper'] = array(
        '#type' => 'item',
        '#description' => t('Your configuration of the Workbench Moderation module has multiple transition paths.<br>Choose the state that you would like the translations to transition to below.'),
      );
      $header = array(
        'Current State',
        'Transitions to',
      );
      $form['defaults']['lingotek_sync_wb']['wb_select']['wb_table'] = array(
        '#type' => 'container',
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => array(),
      );
      foreach ($transition_select as $from_state => $to_states) {
        $selected = isset($form_state['values']['lingotek_sync_wb_select_' . $from_state]) ? $form_state['values']['lingotek_sync_wb_select_' . $from_state] : '';

        // get default
        $select_str = '<div class="form-item form-type-select form-item-lingotek-sync-wb-select-' . $from_state . '">';

        // HTML for a Drupal form select element
        $select_str .= '<select id="lingotek_sync_wb_select_' . $from_state . '" name="lingotek_sync_wb_select_' . $from_state . '"';
        $select_str .= ' class="form-select">';
        foreach ($to_states as $state) {
          $select_str .= '<option ';
          $select_str .= 'value="' . $state . '"';
          if ($selected && $selected == $state) {

            // select default
            $select_str .= ' selected="selected"';
          }
          $select_str .= '>' . $state . '</option>';
        }

        // foreach option add to string
        $select_str .= '</select></div>';
        $form['defaults']['lingotek_sync_wb']['wb_select']['wb_table']['#rows'][] = array(
          array(
            'data' => $from_state,
            'width' => '20%',
          ),
          array(
            'data' => $select_str,
            'width' => '80%',
          ),
        );

        // Get out of _POST
      }
    }
  }
  if ($is_enterprise) {

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

    /*
     * Misc. Options
     */

    // 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, and check \"Enable Lingotek Translation\" for the Title field."),
      '#options' => lingotek_get_url_alias_translations(),
      '#default_value' => $form_state['values']['url_alias_translation'],
    );
  }

  // Workflows
  $workflows = $api
    ->listWorkflows();
  if ($workflows && count($workflows) > 1) {
    $profiles = variable_get('lingotek_profiles');
    $profile_id = isset($form['defaults']['profile_id']['#value']) ? $form['defaults']['profile_id']['#value'] : -1;
    $curr_workflow_id = isset($profiles[$profile_id]['workflow_id']) ? $profiles[$profile_id]['workflow_id'] : '';
    $form['defaults']['workflow_id'] = array(
      '#type' => 'select',
      '#title' => t('Default Workflow'),
      '#description' => t('The default Workflow to use when translating content.'),
      '#default_value' => $curr_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' => 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' => $curr_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' => $curr_workflow_id,
          ),
          ':input[name="prefill_phases_checkbox"]' => array(
            'checked' => true,
          ),
        ),
      ),
      '#suffix' => '</div>',
    );
    $form['defaults']['prefill_phase_select']['#options'] = lingotek_get_phases_by_workflow_id($form_state['values']['workflow_id']);
  }

  // FUTURE-ONLY STUFF
  $form['defaults']['future_only_note'] = array(
    '#type' => 'markup',
    '#markup' => '<h3>' . t('Profile settings impacting only new nodes') . '</h3><hr />',
  );
  $form['defaults']['lingotek_nodes_translation_method'] = array(
    '#type' => 'radios',
    '#title' => t('Translation Storage'),
    '#options' => array(
      'field' => '<strong>Field Translation</strong> (Recommended) - all translations are stored in a single node',
      'node' => '<strong>Node Translation</strong>  - create a new node per language ',
    ),
    'field' => array(
      '#description' => 'A newer and recommended method. Newer versions of Drupal are expected to use this method.',
    ),
    'node' => array(
      '#description' => 'The classical method. Use for backwards compatibility.',
    ),
    '#default_value' => isset($form_state['values']['lingotek_nodes_translation_method']) ? $form_state['values']['lingotek_nodes_translation_method'] : 'field',
  );
  if ($is_enterprise) {

    // 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);
      }
    }
    $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();
      }
    }
    $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' => 'Save',
  );
  $profile_id = $form_state['values']['profile_id'];
  $first_custom_id = 2;
  $is_custom_profile_id = $profile_id >= $first_custom_id;
  if (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' => 'Delete',
    );
  }
  else {
    $markup = $is_custom_profile_id ? t('You can only delete this profile when there are no nodes or content types 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' => 'Cancel',
  );
  return $form;
}