You are here

function tmgmt_local_translation_form in Translation Management Tool 7

Form callback for translating a job item.

1 string reference to 'tmgmt_local_translation_form'
TMGMTLocalTaskItem::buildContent in translators/tmgmt_local/entity/tmgmt_local.entity.task_item.inc
Builds a structured array representing the entity's content.

File

translators/tmgmt_local/includes/tmgmt_local.pages.inc, line 133
Provides page and forms callbacks.

Code

function tmgmt_local_translation_form($form, &$form_state, TMGMTLocalTaskItem $task_item) {
  $form_state['task'] = $task_item
    ->getTask();
  $form_state['task_item'] = $task_item;
  $form_state['job_item'] = $job_item = $task_item
    ->getJobItem();
  $job = $job_item
    ->getJob();
  if ($job
    ->getSetting('job_comment')) {
    $form['job_comment'] = array(
      '#type' => 'item',
      '#title' => t('Job comment'),
      '#markup' => filter_xss($job
        ->getSetting('job_comment')),
    );
  }
  $form['translation'] = array(
    '#type' => 'container',
  );

  // Build the translation form.
  $data = $job_item
    ->getData();

  // Need to keep the first hierarchy. So flatten must take place inside
  // of the foreach loop.
  $zebra = 'even';

  // Reverse the order to get the correct order.
  foreach (array_reverse(element_children($data)) as $key) {
    $flattened = tmgmt_flatten_data($data[$key], $key);
    $form['translation'][$key] = tmgmt_local_translation_form_element($flattened, $task_item, $zebra);
  }

  // Add the form actions as well.
  $form['actions']['#type'] = 'actions';
  $form['actions']['save_as_completed'] = array(
    '#type' => 'submit',
    '#validate' => array(
      'tmgmt_local_translation_form_save_as_completed_validate',
    ),
    '#submit' => array(
      'tmgmt_local_translation_form_save_submit',
      'tmgmt_local_translation_form_save_as_completed_submit',
    ),
    '#value' => t('Save as completed'),
  );
  $form['actions']['save'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'tmgmt_local_translation_form_save_submit',
    ),
    '#value' => t('Save'),
  );
  return $form;
}