public function LingotekSettingsContentSingleForm::submitForm in Lingotek Translation 3.0.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.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.7.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 136
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();
$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)) {
$lingotek_config
->setEnabled($entity_id, $bundle_id);
}
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) {
$lingotek_config
->setFieldLingotekEnabled($entity_id, $bundle_id, $field_id);
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'];
$lingotek_config
->setFieldPropertiesLingotekEnabled($entity_id, $bundle_id, $field_id, $property_values);
}
}
elseif ($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);
}
}
}
if (isset($form_values[$entity_id][$bundle_id]['profiles'])) {
$lingotek_config
->setDefaultProfileId($entity_id, $bundle_id, $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.
$lingotek_config
->setEnabled($entity_id, $bundle_id, FALSE);
}
}
// There is some bug than local tasks block cache is not cleared. Let's do
// that manually.
$this
->invalidateLocalTaskCacheBlocks();
$form_state
->setRedirect('lingotek.settings');
parent::submitForm($form, $form_state);
}