public function LingotekMetadataEditForm::saveMetadata in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8 src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 8.2 src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 4.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.0.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.1.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.2.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.3.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.4.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.5.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.6.x src/Form/LingotekMetadataEditForm.php \Drupal\lingotek\Form\LingotekMetadataEditForm::saveMetadata()
- 3.7.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 191
Class
Namespace
Drupal\lingotek\FormCode
public function saveMetadata(array &$form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
if ($lingotek_config
->isEnabled($entity
->getEntityTypeId(), $entity
->bundle())) {
$input = $form_state
->getUserInput();
$lingotek_document_id = $input['lingotek_document_id'];
$source_status = $input['lingotek_source_status'];
$profile = $input['lingotek_source_status'];
$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]);
}
/** @var \Drupal\lingotek\Entity\LingotekContentMetadata|NULL $metadata */
$metadata = $entity
->hasField('lingotek_metadata') ? $entity->lingotek_metadata->entity : NULL;
if ($metadata !== NULL) {
$metadata
->setProfile($input['lingotek_translation_management']['lingotek_translation_profile']);
$metadata
->setJobId($input['lingotek_job_id']);
$metadata
->save();
}
$this
->messenger()
->addStatus($this
->t('Metadata saved successfully'));
}
else {
$this
->messenger()
->addError($this
->t('This entity cannot be managed in Lingotek. Please check your configuration.'));
}
}