diff -u b/src/TMGMTResponse.php b/src/TMGMTResponse.php --- b/src/TMGMTResponse.php +++ b/src/TMGMTResponse.php @@ -13,25 +13,25 @@ class TMGMTResponse { /** - * True or False for response. + * TRUE or FALSE for response. * * @var boolean */ - public $success; + protected $success; /** - * Message in case bit is false. + * Message in case bit is FALSE. * * @var string */ - public $message; + protected $message; /** * Argument about the error. * * @var array */ - public $data; + protected $args; /** * Constructs a new TMGMT Response Object. @@ -48,6 +48,21 @@ if (!$success) { - $this->$message = $message; - $this->data = $args; + $this->message = $message; + $this->args = $args; } } + + /** + * Returns the object message. + */ + public function getMessage() { + $argumented_message = t($this->message, $this->args); + return $argumented_message; + } + + /** + * Returns the object state on success. + */ + public function getSuccess() { + return $this->success; + } } only in patch2: unchanged: --- a/src/Entity/Translator.php +++ b/src/Entity/Translator.php @@ -322,15 +322,7 @@ class Translator extends ConfigEntityBase implements TranslatorInterface { return FALSE; } - /** - * {@inheritdoc} - */ - public function getNotAvailableReason() { - if ($controller = $this->getPlugin()) { - return $controller->getNotAvailableReason($this); - } - return FALSE; - } + /** * {@inheritdoc} only in patch2: unchanged: --- a/src/Form/JobForm.php +++ b/src/Form/JobForm.php @@ -17,6 +17,7 @@ use Drupal\Core\Url; use Drupal\tmgmt\Entity\Job; use Drupal\tmgmt\Entity\JobItem; use Drupal\tmgmt\JobInterface; +use Drupal\tmgmt\TMGMTResponse; use Drupal\views\Views; /** @@ -422,7 +423,8 @@ class JobForm extends TmgmtFormBase { // Check translator availability. if (!empty($translator)) { if (!$translator->isAvailable()) { - $form_state->setErrorByName('translator', $translator->getNotAvailableReason()); + $result = new TMGMTResponse(FALSE, t('@translator is not available. Make sure it is properly !configured.'), array('@translator' => $translator->label(), '!configured' => $translator->link(t('configured')))); + $form_state->setErrorByName('translator', $result->getMessage()); } elseif (!$translator->canTranslate($job)) { $form_state->setErrorByName('translator', $translator->getNotCanTranslateReason($job)); @@ -498,7 +500,8 @@ class JobForm extends TmgmtFormBase { return $form; } if (!$translator->isAvailable()) { - $form['#description'] = Xss::filter($job->getTranslator()->getNotAvailableReason()); + $result = new TMGMTResponse(FALSE, t('@translator is not available. Make sure it is properly !configured.'), array('@translator' => $translator->label(), '!configured' => $translator->link(t('configured')))); + $form['#description'] = Xss::filter($result->getMessage()); } // @todo: if the target language is not defined, the check will not work if the first language in the list is not available. elseif ($job->getTargetLangcode() && !$translator->canTranslate($job)) { only in patch2: unchanged: --- a/src/Tests/TMGMTUiTest.php +++ b/src/Tests/TMGMTUiTest.php @@ -249,6 +249,13 @@ class TMGMTUiTest extends TMGMTTestBase { $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language'); $this->assertFieldByXPath('//select[@id="edit-translator"]/option[1]', 'Test translator (auto created)'); + // Test for Unavailable/Unconfigured Translators. + $this->default_translator->setSetting('action', 'not_translatable'); + $this->default_translator->save(); + $this->drupalGet(t('admin/tmgmt/jobs/@jobs', array('@jobs' => $job->id()))); + $this->drupalPostForm(NULL, array(), t('Submit to translator')); + $this->assertUniqueText(t('1 error has been found:')); + // Login as administrator to delete a job. $this->loginAsAdmin(); $this->drupalGet('admin/tmgmt/jobs'); only in patch2: unchanged: --- a/src/TranslatorInterface.php +++ b/src/TranslatorInterface.php @@ -155,11 +155,6 @@ interface TranslatorInterface extends ConfigEntityInterface { /** * @todo Remove this once http://drupal.org/node/1420364 is done. - */ - public function getNotAvailableReason(); - - /** - * @todo Remove this once http://drupal.org/node/1420364 is done. * * * @param \Drupal\tmgmt\JobInterface $job * The Job entity that should be translated. only in patch2: unchanged: --- a/src/TranslatorPluginBase.php +++ b/src/TranslatorPluginBase.php @@ -173,12 +173,6 @@ abstract class TranslatorPluginBase extends PluginBase implements TranslatorPlug return t('@translator can not translate from @source to @target.', array('@translator' => $job->getTranslator()->label(), '@source' => $job->getSourceLanguage()->getName(), '@target' => $job->getTargetLanguage()->getName())); } - /** - * {@inheritdoc} - */ - public function getNotAvailableReason(TranslatorInterface $translator) { - return t('@translator is not available. Make sure it is properly !configured.', array('@translator' => $this->pluginDefinition['label'], '!configured' => $translator->link(t('configured')))); - } /** * {@inheritdoc} only in patch2: unchanged: --- a/src/TranslatorPluginInterface.php +++ b/src/TranslatorPluginInterface.php @@ -27,18 +27,7 @@ interface TranslatorPluginInterface extends PluginInspectionInterface { */ public function isAvailable(TranslatorInterface $translator); - /** - * Return a reason why the translator is not available. - * - * @param TranslatorInterface $translator - * The translator entity. - * - * Might be called when isAvailable() returns FALSE to get a reason that - * can be displayed to the user. - * - * @todo Remove this once http://drupal.org/node/1420364 is done. - */ - public function getNotAvailableReason(TranslatorInterface $translator); + /** * Check whether this service can handle a particular translation job.