You are here

function lingotek_get_change_workflow_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.module \lingotek_get_change_workflow_form()
  2. 7.4 lingotek.module \lingotek_get_change_workflow_form()
  3. 7.5 lingotek.module \lingotek_get_change_workflow_form()
1 string reference to 'lingotek_get_change_workflow_form'
lingotek_change_workflow in ./lingotek.bulk_grid.inc
Callback function to change workflow for multiple nodes at a time

File

./lingotek.module, line 2276

Code

function lingotek_get_change_workflow_form($form, &$form_state, $node = NULL) {
  $second_run = isset($form_state['triggering_element']);
  $bulk_grid = FALSE;
  $multiple = FALSE;
  $curr_workflow_id = '';
  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));
      $curr_workflow_id = $node->lingotek['workflow_id'];
    }
    else {
      if (!$second_run) {
        drupal_set_message(t('You will be changing the workflow 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');
  $title = t('Change Workflow');

  // Vertical Tab.
  $form['lingotek'] = array(
    '#title' => t('Change Workflow'),
    '#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,
      )),
    );

    // This is a target node and thus should not have lingotek settings.
    return $form;
  }
  if (isset($nids)) {
    $form['lingotek']['nids'] = array(
      '#type' => 'hidden',
      '#default_value' => json_encode($nids),
    );
  }
  $form['lingotek']['lingotek_note'] = array(
    '#type' => 'item',
    '#title' => $title,
    '#description' => t("This option allows you to replace the current workflow with a new workflow. This will result in the removal of any existing translations. You can optionally restore those translations to a phase in the new workflow."),
  );
  $api = LingotekApi::instance();
  if ($workflows = $api
    ->listWorkflows()) {
    if (!isset($form_state['values']['workflow_id'])) {
      $keys = array_keys($workflows);
      $form_state['values']['workflow_id'] = $keys[0];
    }
    $form['lingotek']['workflow_id'] = array(
      '#type' => 'select',
      '#title' => t('Workflow'),
      '#description' => t('Choose the Workflow'),
      '#options' => $workflows,
      '#default_value' => $curr_workflow_id,
      '#empty_option' => '(select one)',
      '#ajax' => array(
        'callback' => 'lingotek_get_change_workflow_form_callback',
        'wrapper' => 'prefill-phases-div',
        'method' => 'replace',
        'effect' => 'fade',
      ),
      '#prefix' => '<div id="prefill-phases-div">',
    );
    $form['lingotek']['prefill_phases_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => t('Restore to a phase in the new workflow'),
      '#default_value' => TRUE,
      '#description' => t('Prefill the new workflow with translations from the previous workflow'),
      '#states' => array(
        'invisible' => array(
          ':input[name="lingotek[workflow_id]"]' => array(
            'value' => $curr_workflow_id,
          ),
        ),
      ),
    );
    $form['lingotek']['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="lingotek[workflow_id]"]' => array(
            '!value' => $curr_workflow_id,
          ),
          ':input[name="lingotek[prefill_phases_checkbox]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#suffix' => '</div>',
    );
    if (isset($form_state['values']['lingotek']['workflow_id']) && $form_state['values']['lingotek']['workflow_id'] != NULL) {
      $form['lingotek']['prefill_phase_select']['#options'] = lingotek_get_phases_by_workflow_id($form_state['values']['lingotek']['workflow_id']);
    }
    else {
      $form['lingotek']['prefill_phase_select']['#options'] = lingotek_get_phases_by_workflow_id($form_state['values']['workflow_id']);
    }
  }
  if ($bulk_grid) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#submit' => array(
        'lingotek_get_change_workflow_form_submit',
      ),
    );
  }
  return $form;
}