diff --git a/sources/tmgmt_config/src/Tests/ConfigSourceUiTest.php b/sources/tmgmt_config/src/Tests/ConfigSourceUiTest.php index 72a4589..d39322a 100644 --- a/sources/tmgmt_config/src/Tests/ConfigSourceUiTest.php +++ b/sources/tmgmt_config/src/Tests/ConfigSourceUiTest.php @@ -117,6 +117,28 @@ class ConfigSourceUiTest extends EntityTestBase { } } $this->assertEqual($counter, 2); + + // Test that a job can not be accepted if the translator does not exist. + // Request an italian translation. + $edit = array( + 'languages[it]' => TRUE, + ); + $this->drupalPostForm(NULL, $edit, t('Request translation')); + + // Go back to the originally defined destination URL without submitting. + $this->drupalGet('admin/structure/types/manage/article/translate'); + + // Verify that the pending translation is shown. + $this->clickLink(t('In progress')); + + // Try to save, should fail because the job has no translator assigned. + $edit = array( + 'name[translation]' => $this->randomMachineName(), + ); + $this->drupalPostForm(NULL, $edit, t('Save')); + + // Verify that we are on the checkout page. + $this->assertResponse(200); } /** diff --git a/src/Form/JobItemForm.php b/src/Form/JobItemForm.php index 2ad5c2a..90e53d7 100644 --- a/src/Form/JobItemForm.php +++ b/src/Form/JobItemForm.php @@ -201,7 +201,7 @@ class JobItemForm extends TmgmtFormBase { $source_ui = $this->sourceManager->createUIInstance($item->getPlugin()); $source_ui->reviewFormValidate($form, $form_state, $item); // Invoke the validation method on the translator controller (if available). - if ($item->getTranslator()) { + if ($item->hasTranslator()) { $translator_ui = $this->translatorManager->createUIInstance($item->getTranslator()->getPluginId()); $translator_ui->reviewFormValidate($form, $form_state, $item); } @@ -225,30 +225,30 @@ class JobItemForm extends TmgmtFormBase { $source_ui = $this->sourceManager->createUIInstance($item->getPlugin()); $source_ui->reviewFormSubmit($form, $form_state, $item); // Invoke the submit method on the translator controller (if available). - if ($item->getTranslator()){ + if ($item->hasTranslator()) { $translator_ui = $this->translatorManager->createUIInstance($item->getTranslator()->getPluginId()); $translator_ui->reviewFormSubmit($form, $form_state, $item); - } - // Write changes back to item. - foreach ($form_state->getValues() as $key => $value) { - if (is_array($value) && isset($value['translation'])) { - // Update the translation, this will only update the translation in case - // it has changed. We have two different cases, the first is for nested - // texts. - if (is_array($value['translation'])) { - $data = array( - '#text' => $value['translation']['value'], - '#origin' => 'local', - ); - } - else { - $data = array( - '#text' => $value['translation'], - '#origin' => 'local', - ); - } - $item->addTranslatedData($data, $key); + // Write changes back to item. + foreach ($form_state->getValues() as $key => $value) { + if (is_array($value) && isset($value['translation'])) { + // Update the translation, this will only update the translation in case + // it has changed. We have two different cases, the first is for nested + // texts. + if (is_array($value['translation'])) { + $data = array( + '#text' => $value['translation']['value'], + '#origin' => 'local', + ); + } else { + $data = array( + '#text' => $value['translation'], + '#origin' => 'local', + ); + } + + $item->addTranslatedData($data, $key); + } } } // Check if the user clicked on 'Accept', 'Submit' or 'Reject'.