You are here

public function LingotekMetadataEditForm::buildForm in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  2. 4.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  3. 3.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  4. 3.1.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  5. 3.2.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  6. 3.3.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  7. 3.4.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  8. 3.5.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  9. 3.6.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  10. 3.7.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  11. 3.8.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/LingotekMetadataEditForm.php, line 102

Class

LingotekMetadataEditForm

Namespace

Drupal\lingotek\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  if ($redirect = $this
    ->checkSetup()) {
    return $redirect;
  }

  // $form = parent::buildForm($form, $form_state);
  $entity = $this
    ->getEntity();
  $lingotek_document_id = $this->translationService
    ->getDocumentId($entity);
  $source_status = $this->translationService
    ->getSourceStatus($entity);
  $form['metadata']['notice'] = [
    '#markup' => $this
      ->t('Editing the metadata manually can cause diverse errors. If you find yourself using it often, please contact the module maintainers because you may have hit a bug.'),
    '#prefix' => '<span class="warning">',
    '#suffix' => '</span',
  ];
  $form['metadata']['lingotek_document_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Lingotek Document ID'),
    '#default_value' => $lingotek_document_id,
  ];
  $form['metadata']['lingotek_source_status'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Lingotek Source Status'),
    '#default_value' => $source_status,
    '#options' => $this
      ->getLingotekStatusesOptions(),
  ];
  $languages = $this->languageManager
    ->getLanguages();
  foreach ($languages as $langcode => $language) {
    $form['metadata']['lingotek_target_status'][$langcode] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Lingotek Target Status: ') . $language
        ->getName(),
      '#default_value' => $this->translationService
        ->getTargetStatus($entity, $langcode),
      '#options' => $this
        ->getLingotekStatusesOptions(),
    ];
  }
  $form['actions'] = [];
  $form['actions']['save_metadata'] = array(
    '#type' => 'submit',
    '#value' => t('Save metadata'),
    '#button_type' => 'primary',
    '#limit_validation_errors' => array(),
    '#submit' => [
      [
        $this,
        'saveMetadata',
      ],
    ],
  );
  return $form;
}