You are here

public function GlobalLinkTranslator::checkAvailable in GlobalLink Connect for Drupal 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/tmgmt/Translator/GlobalLinkTranslator.php \Drupal\globallink\Plugin\tmgmt\Translator\GlobalLinkTranslator::checkAvailable()

Checks whether a translator is available.

Parameters

TranslatorInterface $translator: The translator entity.

Return value

\Drupal\tmgmt\Translator\AvailableResult The result of the availability check.

Overrides TranslatorPluginBase::checkAvailable

File

src/Plugin/tmgmt/Translator/GlobalLinkTranslator.php, line 671

Class

GlobalLinkTranslator
GlobalLink translation plugin controller.

Namespace

Drupal\globallink\Plugin\tmgmt\Translator

Code

public function checkAvailable(TranslatorInterface $translator) {

  // One time per request should be enough if available.
  $available =& drupal_static(__METHOD__, FALSE);
  if ($available === FALSE) {
    try {
      $settings = $translator
        ->getSettings();
      $pd_config = $this->glExchangeAdapter
        ->getPDConfig($settings);
      $this->glExchangeAdapter
        ->getGlExchange($pd_config);
    } catch (\Exception $e) {
      return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
        '@translator' => $translator
          ->label(),
        ':configured' => $translator
          ->url(),
      ]));
    }
    $available = TRUE;
  }
  return AvailableResult::yes();
}