function ConfigTranslateForm::submitForm in Translation Management Tool 8
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 FormInterface::submitForm
File
- sources/
tmgmt_config/ src/ Form/ ConfigTranslateForm.php, line 189
Class
- ConfigTranslateForm
- Configuration translation overview form.
Namespace
Drupal\tmgmt_config\FormCode
function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\config_translation\ConfigMapperManagerInterface $mapper */
$mapper = $form_state
->get('mapper');
$values = $form_state
->getValues();
$item_type = $form_state
->get('item_type');
$item_id = $form_state
->get('item_id');
$jobs = array();
foreach (array_keys(array_filter($values['languages'])) as $langcode) {
// Create the job object.
$job = tmgmt_job_create($mapper
->getLangcode(), $langcode, \Drupal::currentUser()
->id());
try {
// Add the job item.
$job
->addItem('config', $item_type, $item_id);
// Append this job to the array of created jobs so we can redirect the user
// to a multistep checkout form if necessary.
$jobs[$job
->id()] = $job;
} catch (TMGMTException $e) {
watchdog_exception('tmgmt', $e);
$languages = \Drupal::languageManager()
->getLanguages();
$target_lang_name = $languages[$langcode]->language;
$this
->messenger()
->addError(t('Unable to add job item for target language %name. Make sure the source content is not empty.', array(
'%name' => $target_lang_name,
)));
}
}
\Drupal::service('tmgmt.job_checkout_manager')
->checkoutAndRedirect($form_state, $jobs);
}