diff -u b/src/Entity/Translator.php b/src/Entity/Translator.php --- b/src/Entity/Translator.php +++ b/src/Entity/Translator.php @@ -300,7 +300,7 @@ if ($controller = $this->getPlugin()) { return $controller->canTranslate($this, $job); } - return FALSE; + return new TMGMTResponse(FALSE); } /** @@ -310,7 +310,11 @@ if ($controller = $this->getPlugin()) { return $controller->isAvailable($this); } - return new TMGMTResponse(FALSE, t('@translator is not available. Make sure it is properly !configured.'), array('@translator' => $this->label(), '!configured' => $this->link(t('configured')))); + return new TMGMTResponse(FALSE, t('@translator is not available. Make sure it is properly !configured.'), [ + '@translator' => $this->label(), + '!configured' => $this->link(t('configured') + ) + ]); } /** @@ -323,18 +327,6 @@ return FALSE; } - - - /** - * {@inheritdoc} - */ - public function getNotCanTranslateReason(JobInterface $job) { - if ($controller = $this->getPlugin()) { - return $controller->getNotCanTranslateReason($job); - } - return FALSE; - } - /** * {@inheritdoc} */ diff -u b/src/Form/JobForm.php b/src/Form/JobForm.php --- b/src/Form/JobForm.php +++ b/src/Form/JobForm.php @@ -427,8 +427,8 @@ // $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)); + elseif (!$translator->canTranslate($job)->getSuccess()) { + $form_state->setErrorByName('translator', $translator->canTranslate($job)->getMessage()); } } } @@ -505,8 +505,8 @@ $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)) { - $form['#description'] = Xss::filter($job->getTranslator()->getNotCanTranslateReason($job)); + elseif ($job->getTargetLangcode() && !$translator->canTranslate($job)->getSuccess()) { + $form['#description'] = Xss::filter($job->getTranslator()->canTranslate($job)->getMessage()); } else { $plugin_ui = $this->translatorManager->createUIInstance($translator->getPluginId()); diff -u b/src/TranslatorInterface.php b/src/TranslatorInterface.php --- b/src/TranslatorInterface.php +++ b/src/TranslatorInterface.php @@ -132,7 +132,7 @@ * @param \Drupal\tmgmt\JobInterface Job * The Job entity that should be translated. * - * @return bool + * @return TMGMTResponse * TRUE if the job can be processed and translated, FALSE otherwise. */ public function canTranslate(JobInterface $job); @@ -154,14 +154,6 @@ public function hasCheckoutSettings(JobInterface $job); /** - * @todo Remove this once http://drupal.org/node/1420364 is done. - * - * * @param \Drupal\tmgmt\JobInterface $job - * The Job entity that should be translated. - */ - public function getNotCanTranslateReason(JobInterface $job); - - /** * Maps local language to remote language. * * @param string $language diff -u b/src/TranslatorPluginBase.php b/src/TranslatorPluginBase.php --- b/src/TranslatorPluginBase.php +++ b/src/TranslatorPluginBase.php @@ -54,7 +54,7 @@ // one of the supported languages. return new TMGMTResponse(TRUE); } - return FALSE; + return new TMGMTResponse(FALSE, t('@translator can not translate because is not available', array('@translator' => $translator->label()))); } /** @@ -169,14 +169,6 @@ /** * {@inheritdoc} */ - public function getNotCanTranslateReason(JobInterface $job) { - 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 defaultSettings() { $defaults = array('auto_accept' => FALSE); // Check if any default settings are defined in the plugin info. diff -u b/src/TranslatorPluginInterface.php b/src/TranslatorPluginInterface.php --- b/src/TranslatorPluginInterface.php +++ b/src/TranslatorPluginInterface.php @@ -37,25 +37,12 @@ * @param \Drupal\tmgmt\JobInterface $job * The Job entity that should be translated. * - * @return boolean + * @return TMGMTResponse * TRUE if the job can be processed and translated, FALSE otherwise. */ public function canTranslate(TranslatorInterface $translator, JobInterface $job); /** - * Return a reason why the translator is not able to translate this job. - * - * @param \Drupal\tmgmt\JobInterface $job - * The job entity. - * - * Might be called when canTranslate() 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 getNotCanTranslateReason(JobInterface $job); - - /** * Specifies default mappings for local to remote language codes. * * This method can be used in case we know in advance what language codes are diff -u b/tmgmt.module b/tmgmt.module --- b/tmgmt.module +++ b/tmgmt.module @@ -391,7 +391,7 @@ function tmgmt_translator_load_available($job) { $translators = Translator::loadMultiple(); foreach ($translators as $name => $translator) { - if (!$translator->isAvailable()->getSuccess() || (isset($job) && !$translator->canTranslate($job))) { + if (!$translator->isAvailable()->getSuccess() || (isset($job) && !$translator->canTranslate($job)->getSuccess())) { unset($translators[$name]); } } @@ -471,7 +471,7 @@ if (!$translator->isAvailable()->getSuccess()) { $labels[$translator->id()] = t('@label (not available)', array('@label' => $translator->label())); } - elseif (isset($job) && !$translator->canTranslate($job)) { + elseif (isset($job) && !$translator->canTranslate($job)->getSuccess()) { $labels[$translator->id()] = t('@label (unsupported)', array('@label' => $translator->label())); } else { only in patch2: unchanged: --- a/src/Entity/Job.php +++ b/src/Entity/Job.php @@ -18,6 +18,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\tmgmt\JobInterface; use Drupal\tmgmt\JobItemInterface; use Drupal\tmgmt\TMGMTException; +use Drupal\tmgmt\TMGMTResponse; use Drupal\user\EntityOwnerInterface; use Drupal\user\UserInterface; @@ -494,10 +495,10 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac public function canRequestTranslation() { if ($translator = $this->getTranslator()) { if ($translator->canTranslate($this)) { - return TRUE; + return new TMGMTResponse(TRUE); } } - return FALSE; + return new TMGMTResponse(FALSE, t('Translation cant be requested')); } /** only in patch2: unchanged: --- a/tmgmt_test/src/Plugin/tmgmt/Translator/TestTranslator.php +++ b/tmgmt_test/src/Plugin/tmgmt/Translator/TestTranslator.php @@ -11,6 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\tmgmt\Entity\Translator; use Drupal\tmgmt\JobInterface; use Drupal\tmgmt\JobItemInterface; +use Drupal\tmgmt\TMGMTResponse; use Drupal\tmgmt\TranslatorInterface; use Drupal\tmgmt\TranslatorPluginBase; use Drupal\tmgmt\TranslatorRejectDataInterface; @@ -99,7 +100,11 @@ class TestTranslator extends TranslatorPluginBase implements TranslatorRejectDat */ function canTranslate(TranslatorInterface $translator, JobInterface $job) { if ($job->getSetting('action') == 'not_translatable') { - return FALSE; + return new TMGMTResponse(FALSE, t('@translator can not translate from @source to @target.', array( + '@translator' => $job->getTranslator()->label(), + '@source' => $job->getSourceLanguage()->getName(), + '@target' => $job->getTargetLanguage()->getName() + ))); } return parent::canTranslate($translator, $job); } only in patch2: unchanged: --- a/translators/tmgmt_file/src/Plugin/tmgmt/Translator/FileTranslator.php +++ b/translators/tmgmt_file/src/Plugin/tmgmt/Translator/FileTranslator.php @@ -8,6 +8,7 @@ namespace Drupal\tmgmt_file\Plugin\tmgmt\Translator; use Drupal\tmgmt\JobInterface; +use Drupal\tmgmt\TMGMTResponse; use Drupal\tmgmt\TranslatorInterface; use Drupal\tmgmt\TranslatorPluginBase; @@ -28,7 +29,7 @@ class FileTranslator extends TranslatorPluginBase { */ public function canTranslate(TranslatorInterface $translator, JobInterface $job) { // Anything can be exported. - return TRUE; + return new TMGMTResponse(TRUE); } /**