You are here

public function LingotekFieldConfigEditForm::submitForm in Lingotek Translation 3.4.x

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

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

File

src/Form/LingotekFieldConfigEditForm.php, line 111

Class

LingotekFieldConfigEditForm
Allow to configure fields translation with Lingotek in the proper field forms

Namespace

Drupal\lingotek\Form

Code

public function submitForm(array $form, FormStateInterface $form_state) {
  $field = $form_state
    ->getFormObject()
    ->getEntity();
  $entity_id = $field
    ->getTargetEntityTypeId();
  $bundle_id = $field
    ->getTargetBundle();
  $field_id = $field
    ->getName();
  $value = $form_state
    ->getValue([
    'third_party_settings',
    'content_translation',
    'translation_sync',
  ]);
  if (isset($value)) {
    $content_translation_field_properties = $form_state
      ->getValue('third_party_settings')['content_translation']['translation_sync'];
    $filtered_field_properties = [];
    foreach ($content_translation_field_properties as $content_translation_field_property_key => $content_translation_field_property) {
      if ($content_translation_field_property && $form_state
        ->getValue('translatable_for_lingotek_properties_' . $content_translation_field_property_key)) {
        $filtered_field_properties[$content_translation_field_property_key] = $content_translation_field_property;
      }
      else {
        $filtered_field_properties[$content_translation_field_property_key] = 0;
        if ($form_state
          ->getValue('translatable_for_lingotek_properties_' . $content_translation_field_property_key)) {
          $this
            ->messenger()
            ->addWarning(t('To translate the image properties with Lingotek, you must enable them for translation first.'));
        }
      }
    }
    $this->lingotekConfig
      ->setFieldPropertiesLingotekEnabled($entity_id, $bundle_id, $field_id, $filtered_field_properties);
  }
  if ($form_state
    ->getValue('translatable_for_lingotek') && $form_state
    ->getValue('translatable')) {
    if (!$this->lingotekConfig
      ->isFieldLingotekEnabled($entity_id, $bundle_id, $field_id)) {
      $this->lingotekConfig
        ->setFieldLingotekEnabled($entity_id, $bundle_id, $field_id);
    }
  }
  else {
    if ($this->lingotekConfig
      ->isFieldLingotekEnabled($entity_id, $bundle_id, $field_id)) {
      $this->lingotekConfig
        ->setFieldLingotekEnabled($entity_id, $bundle_id, $field_id, FALSE);
    }
  }
}