public function LingotekSettingsTabContentForm::submitForm in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8 src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 8.2 src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 4.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.1.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.2.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.3.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.5.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.6.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 3.7.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::submitForm()
- 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 196
Class
- LingotekSettingsTabContentForm
- Configure Lingotek
Namespace
Drupal\lingotek\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$readOnly = FALSE;
if ($this->countTranslatableBundles > self::CONTENT_SINGLE_FORM_THRESHOLD) {
$readOnly = TRUE;
}
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$form_values = $form_state
->getValues();
$contentSettingsData = [];
// 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'] || $readOnly) {
if (!$lingotek_config
->isEnabled($entity_id, $bundle_id) && !$readOnly) {
$contentSettingsData[$entity_id][$bundle_id]['enabled'] = TRUE;
}
if (!$readOnly) {
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);
}
elseif (!$readOnly) {
// If we removed it, unable it.
$contentSettingsData[$entity_id][$bundle_id]['enabled'] = FALSE;
}
}
}
$lingotek_config
->setContentTranslationSettings($contentSettingsData);
parent::submitForm($form, $form_state);
}