public function LingotekSettingsContentSingleForm::submitForm in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 4.0.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.0.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.1.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.2.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.3.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.4.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.5.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.6.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::submitForm()
- 3.8.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::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/ LingotekSettingsContentSingleForm.php, line 134
Class
- LingotekSettingsContentSingleForm
- Configure Lingotek
Namespace
Drupal\lingotek\FormCode
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();
$contentSettingsData = [];
$entity_id = $this->entity_type_id;
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)) {
$contentSettingsData[$entity_id][$bundle_id]['enabled'] = TRUE;
}
foreach ($bundle['fields_container']['fields'] as $field_id => $ignore) {
$field_choice = isset($bundle['fields'][$field_id]) ? $bundle['fields'][$field_id] : 0;
if ($field_choice == 1) {
$contentSettingsData[$entity_id][$bundle_id]['fields'][$field_id] = TRUE;
if (isset($form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties'])) {
// We need to add both arrays, as the first one only includes the checked properties.
$property_values = $form_values[$entity_id][$bundle_id]['fields'][$field_id . ':properties'] + $form_values[$entity_id][$bundle_id]['fields_container']['fields'][$field_id . ':properties'];
$contentSettingsData[$entity_id][$bundle_id]['fields'][$field_id . ':properties'] = $property_values;
}
}
elseif ($field_choice == 0) {
$contentSettingsData[$entity_id][$bundle_id]['fields'][$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);
$contentSettingsData[$entity_id][$bundle_id]['fields'][$field_id . ':properties'] = $properties;
}
}
}
if (isset($form_values[$entity_id][$bundle_id]['profiles'])) {
$contentSettingsData[$entity_id][$bundle_id]['profile'] = $form_values[$entity_id][$bundle_id]['profiles'];
}
/** @var \Drupal\lingotek\Moderation\LingotekModerationFactoryInterface $moderationFactory */
$moderationFactory = \Drupal::service('lingotek.moderation_factory');
/** @var \Drupal\lingotek\Moderation\LingotekModerationSettingsFormInterface $moderationForm */
$moderationForm = $moderationFactory
->getModerationSettingsForm();
$moderationForm
->submitHandler($entity_id, $bundle_id, $bundle);
}
else {
// If we removed it, unable it.
$contentSettingsData[$entity_id][$bundle_id]['enabled'] = FALSE;
}
}
$lingotek_config
->setContentTranslationSettings($contentSettingsData);
$form_state
->setRedirect('lingotek.settings');
parent::submitForm($form, $form_state);
}