You are here

public function LingotekMetadataEditForm::buildForm in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8 src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  2. 8.2 src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  3. 4.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  4. 3.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  5. 3.1.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  6. 3.2.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::buildForm()
  7. 3.3.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 107

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();

  /** @var \Drupal\lingotek\Entity\LingotekContentMetadata|NULL $metadata */
  $metadata = $entity
    ->hasField('lingotek_metadata') ? $entity->lingotek_metadata->entity : NULL;
  $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', [
        '%language' => $language
          ->getName(),
      ]),
      '#default_value' => $this->translationService
        ->getTargetStatus($entity, $langcode),
      '#options' => $this
        ->getLingotekStatusesOptions(),
    ];
  }
  $form['metadata']['lingotek_job_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Lingotek Job ID'),
    '#default_value' => $metadata ? $metadata
      ->getJobId() : '',
  ];
  $encodedMetadata = 'NULL';
  if ($metadata) {
    $encodedMetadata = json_encode($metadata
      ->toArray(), JSON_PRETTY_PRINT);
  }
  $form['metadata']['verbatim_area'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Lingotek Verbatim Metadata'),
    "#collapsible" => TRUE,
    "#collapsed" => TRUE,
    '#tree' => TRUE,
    '#weight' => 50,
  ];
  $form['metadata']['verbatim_area']['verbatim'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Lingotek Verbatim Metadata'),
    '#title_display' => 'invisible',
    '#readonly' => TRUE,
    '#cols' => '80',
    '#rows' => '20',
    '#default_value' => $encodedMetadata,
    '#attributes' => [
      'readonly' => TRUE,
    ],
  ];
  $form['actions'] = [];
  $form['actions']['save_metadata'] = [
    '#type' => 'submit',
    '#value' => t('Save metadata'),
    '#button_type' => 'primary',
    '#limit_validation_errors' => [],
    '#submit' => [
      [
        $this,
        'saveMetadata',
      ],
    ],
  ];
  return $form;
}