You are here

public function LingotekMetadataEditForm::saveMetadata in Lingotek Translation 8

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

Submit handler that saves the metadata of this content entity.

Parameters

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

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

File

src/Form/LingotekMetadataEditForm.php, line 156

Class

LingotekMetadataEditForm

Namespace

Drupal\lingotek\Form

Code

public function saveMetadata(array &$form, FormStateInterface $form_state) {
  $entity = $this
    ->getEntity();
  $input = $form_state
    ->getUserInput();
  $lingotek_document_id = $input['lingotek_document_id'];
  $source_status = $input['lingotek_source_status'];

  // We need to delete the key before inserting it in the table.
  \Drupal::database()
    ->delete('lingotek_content_metadata')
    ->condition('document_id', $lingotek_document_id)
    ->condition('entity_type', $entity
    ->getEntityTypeId())
    ->condition('entity_id', $entity
    ->id())
    ->execute();
  $this->translationService
    ->setDocumentId($entity, $lingotek_document_id);
  $this->translationService
    ->setSourceStatus($entity, $source_status);
  foreach ($this->languageManager
    ->getLanguages() as $langcode => $language) {
    $this->translationService
      ->setTargetStatus($entity, $langcode, $input[$langcode]);
  }
  drupal_set_message($this
    ->t('Metadata saved successfully'));
}