public function LocalTaskItemForm::form

File

translators/tmgmt_local/src/Form/LocalTaskItemForm.php, line 35

Class

LocalTaskItemForm
Form controller for the localTaskItem edit forms.

Namespace

Drupal\tmgmt_local\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $task_item = $this->entity;
  $form['#title'] = $task_item
    ->label();
  $job_item = $task_item
    ->getJobItem();
  $job = $job_item
    ->getJob();
  $form['info'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'tmgmt-local-task-info',
        'clearfix',
      ),
    ),
    '#weight' => 0,
  );
  $url = $job_item
    ->getSourceUrl();
  $form['info']['source'] = array(
    '#type' => 'item',
    '#title' => t('Source'),
    '#markup' => $url ? Link::fromTextAndUrl($job_item
      ->getSourceLabel(), $url)
      ->toString() : $job_item
      ->getSourceLabel(),
    '#prefix' => '<div class="tmgmt-ui-source tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  $form['info']['sourcetype'] = array(
    '#type' => 'item',
    '#title' => t('Source type'),
    '#markup' => $job_item
      ->getSourceType(),
    '#prefix' => '<div class="tmgmt-ui-source-type tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  $form['info']['source_language'] = array(
    '#type' => 'item',
    '#title' => t('Source language'),
    '#markup' => $job_item
      ->getJob()
      ->getSourceLanguage()
      ->getName(),
    '#prefix' => '<div class="tmgmt-ui-source-language tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  $form['info']['target_language'] = array(
    '#type' => 'item',
    '#title' => t('Target language'),
    '#markup' => $job_item
      ->getJob()
      ->getTargetLanguage()
      ->getName(),
    '#prefix' => '<div class="tmgmt-ui-target-language tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  $form['info']['changed'] = array(
    '#type' => 'item',
    '#title' => t('Last change'),
    '#value' => $task_item
      ->getChangedTime(),
    '#markup' => \Drupal::service('date.formatter')
      ->format($task_item
      ->getChangedTime()),
    '#prefix' => '<div class="tmgmt-ui-changed tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  $statuses = LocalTaskItem::getStatuses();
  $form['info']['status'] = array(
    '#type' => 'item',
    '#title' => t('Status'),
    '#markup' => $statuses[$task_item
      ->getStatus()],
    '#prefix' => '<div class="tmgmt-ui-task-item-status tmgmt-ui-info-item">',
    '#suffix' => '</div>',
    '#value' => $task_item
      ->getStatus(),
  );
  $task = $task_item
    ->getTask();
  $url = $task
    ->toUrl();
  $form['info']['task'] = array(
    '#type' => 'item',
    '#title' => t('Task'),
    '#markup' => Link::fromTextAndUrl($task
      ->label(), $url)
      ->toString(),
    '#prefix' => '<div class="tmgmt-ui-task tmgmt-ui-info-item">',
    '#suffix' => '</div>',
  );
  if ($job
    ->getSetting('job_comment')) {
    $form['job_comment'] = array(
      '#type' => 'item',
      '#title' => t('Job comment'),
      '#markup' => Xss::filter($job
        ->getSetting('job_comment')),
    );
  }
  $form['translation'] = array(
    '#type' => 'container',
  );

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

  // Need to keep the first hierarchy. So flatten must take place inside
  // of the foreach loop.
  $zebra = 'even';
  foreach (Element::children($data) as $key) {
    $flattened = \Drupal::service('tmgmt.data')
      ->flatten($data[$key], $key);
    $form['translation'][$key] = $this
      ->formElement($flattened, $task_item, $zebra);
  }
  $form['footer'] = tmgmt_color_local_review_legend();
  $form['#attached']['library'][] = 'tmgmt/admin';
  return $form;
}