You are here

public function LingotekSettingsTabContentForm::submitForm in Lingotek Translation 8

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

Form submission handler.

Parameters

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

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

Overrides ConfigFormBase::submitForm

File

src/Form/LingotekSettingsTabContentForm.php, line 127
Contains \Drupal\lingotek\Form\LingotekSettingsTabContentForm.

Class

LingotekSettingsTabContentForm
Configure Lingotek

Namespace

Drupal\lingotek\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');
  $form_values = $form_state
    ->getValues();
  $data = array();

  // For every content type, save the profile and fields in the Lingotek object
  foreach ($this->translatable_bundles as $entity_id => $bundles) {
    foreach ($form_values[$entity_id] as $bundle_id => $bundle) {

      // Only process if we have marked the checkbox.
      if ($bundle['enabled']) {
        if (!$lingotek_config
          ->isEnabled($entity_id, $bundle_id)) {
          $lingotek_config
            ->setEnabled($entity_id, $bundle_id);
        }
        foreach ($bundle['fields'] as $field_id => $field_choice) {
          if ($field_choice == 1) {
            $lingotek_config
              ->setFieldLingotekEnabled($entity_id, $bundle_id, $field_id);
            if (isset($form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties'])) {
              $lingotek_config
                ->setFieldPropertiesLingotekEnabled($entity_id, $bundle_id, $field_id, $form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties']);
            }
          }
          else {
            if ($field_choice == 0) {
              $lingotek_config
                ->setFieldLingotekEnabled($entity_id, $bundle_id, $field_id, FALSE);
              if (isset($form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties'])) {
                $properties = array_keys($form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties']);
                $properties = array_fill_keys($properties, 0);
                $lingotek_config
                  ->setFieldPropertiesLingotekEnabled($entity_id, $bundle_id, $field_id, $properties);
              }
            }
          }
        }
        $lingotek_config
          ->setDefaultProfileId($entity_id, $bundle_id, $form_values[$entity_id][$bundle_id]['profiles']);
      }
      else {

        // If we removed it, unable it.
        $lingotek_config
          ->setEnabled($entity_id, $bundle_id, FALSE);
      }
    }
  }
  parent::submitForm($form, $form_state);
}