Commit 475b19e2 authored by Primoz Hmeljak's avatar Primoz Hmeljak Committed by Sascha Grossenbacher
Browse files

Issue #3141914 by Berdir, Primsi, Project Update Bot: Drupal 9 compatibility

parent 61889f5b
Loading
Loading
Loading
Loading

composer.json

0 → 100644
+9 −0
Original line number Diff line number Diff line
{
  "name": "drupal/tmgmt_mygengo",
  "description": "Gengo Translator",
  "type": "drupal-module",
  "license": "GPL-2.0+",
  "require": {
    "drupal/tmgmt": "^1.1"
  }
}
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ div.comments-wrapper ul li {
  border: 1px solid silver;
  padding: 10px;
  margin: 0 0 4px;
  background-color: white;
}

div.comments-wrapper ul li:nth-child(2) {
  background-color: #f7f7f7;
}

div.gengo-comment-meta {
+14 −5
Original line number Diff line number Diff line
@@ -64,6 +64,13 @@ class GengoConnector {
   */
  protected $client;

  /**
   * Module extension list.
   *
   * @var \Drupal\Core\Extension\ModuleExtensionList;
   */
  protected $extensionList;

  /**
   * Construct the connector to gengo service.
   *
@@ -76,6 +83,7 @@ class GengoConnector {
    $this->privateKey = $translator->getSetting('api_private_key');
    $this->debug = \Drupal::config('tmgmt_mygengo.settings')->get('tmgmt_mygengo_debug');
    $this->client = $client;
    $this->extensionList = \Drupal::service('extension.list.module');
  }

  /**
@@ -379,7 +387,7 @@ class GengoConnector {
      throw new TMGMTException('Unable to connect to Gengo service due to following error: @error', ['@error' => $response->getReasonPhrase()], $response->getStatusCode());
    }

    $results = json_decode($response->getBody()->getContents(), TRUE);
    $results = json_decode((string) $response->getBody(), TRUE);

    if ($results['opstat'] == 'ok' && isset($results['response'])) {
      return $results['response'];
@@ -408,12 +416,13 @@ class GengoConnector {
   */
  public function getUserAgent() {
    global $base_url;
    $core = '8.x-1.x-dev';

    $info = system_get_info('module', 'tmgmt');
    $tmgmt_version = !empty($info['version']) ? $info['version'] : $info['core'] . '-1.x-dev';
    $info = $this->extensionList->getExtensionInfo('tmgmt');
    $tmgmt_version = !empty($info['version']) ? $info['version'] : $core;

    $info = system_get_info('module', 'tmgmt_mygengo');
    $gengo_version = !empty($info['version']) ? $info['version'] : $info['core'] . '-1.x-dev';
    $info = $this->extensionList->getExtensionInfo('tmgmt_mygengo');
    $gengo_version = !empty($info['version']) ? $info['version'] : $core;

    return 'Drupal TMGMT/' . $tmgmt_version . '; Gengo/' . $gengo_version . '; ' . $base_url;
  }
+11 −10
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

namespace Drupal\tmgmt_mygengo;

use Drupal\Core\Link;
use Drupal;
use Drupal\Core\Url;
use Drupal\tmgmt\TranslatorPluginUiBase;
@@ -242,20 +243,20 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    /** @var \Drupal\tmgmt\TranslatorInterface $translator */
    $translator = $form_state->getFormObject()->getEntity();
    $url = Url::fromUri('https://gengo.com/account/api_settings/');
    $gengo_key_url = \Drupal::l(t('Gengo Api Settings'), $url);
    $gengo_key_url = Link::fromTextAndUrl(t('Gengo Api Settings'), $url);
    $form['api_public_key'] = array(
      '#type' => 'textfield',
      '#title' => t('Gengo API Public key'),
      '#required' => TRUE,
      '#default_value' => $translator->getSetting('api_public_key'),
      '#description' => t('Please enter your Gengo API Public key or visit @link to create a new one', array('@link' => $gengo_key_url)),
      '#description' => t('Please enter your Gengo API Public key or visit @link to create a new one', array('@link' => $gengo_key_url->toString())),
    );
    $form['api_private_key'] = array(
      '#type' => 'textfield',
      '#title' => t('Gengo API Private key'),
      '#required' => TRUE,
      '#default_value' => $translator->getSetting('api_private_key'),
      '#description' => t('Please enter your Gengo API Private key or visit @link to create a new one', array('@link' => $gengo_key_url)),
      '#description' => t('Please enter your Gengo API Private key or visit @link to create a new one', array('@link' => $gengo_key_url->toString())),
    );
    $form['mygengo_auto_approve'] = array(
      '#type' => 'checkbox',
@@ -351,7 +352,7 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    $settings['eta'] = array(
      '#type' => 'item',
      '#title' => t('ETA'),
      '#markup' => format_date(time() + $quote['highest_eta'], "long"),
      '#markup' => \Drupal::service('date.formatter')->format(time() + $quote['highest_eta'], "long"),
    );

    $settings['comment'] = array(
@@ -404,7 +405,7 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    }
    catch (TMGMTException $e) {
      watchdog_exception('tmgmt_mygengo', $e);
      drupal_set_message($e->getMessage(), 'error');
      $this->messenger()->addError($e->getMessage());
    }

    // Setup empty values.
@@ -457,7 +458,7 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    }
    catch (TMGMTException $e) {
      watchdog_exception('tmgmt_mygengo', $e);
      drupal_set_message($e->getMessage(), 'error');
      $this->messenger()->addError($e->getMessage());
    }

    return $credit_info;
@@ -496,7 +497,7 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    }
    catch (TMGMTException $e) {
      watchdog_exception('tmgmt_mygengo', $e);
      drupal_set_message($e->getMessage(), 'error');
      $this->messenger()->addError($e->getMessage());
    }

    foreach ($gengo_language_pairs as $tier) {
@@ -540,7 +541,7 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
    $cid = 'tmgmt_mygengo_comments_' . $gengo_job_id;
    $cache =  \Drupal::cache('data')->get($cid);

    if (isset($cache->data) && !$reload && $cache->expire > REQUEST_TIME) {
    if (isset($cache->data) && !$reload && $cache->expire > \Drupal::time()->getRequestTime()) {
      return $cache->data;
    }

@@ -551,11 +552,11 @@ class MyGengoTranslatorUi extends TranslatorPluginUiBase {
      $response = $connector->getComments($gengo_job_id);

      $data = isset($response['thread']) ? $response['thread'] : NULL;
      \Drupal::cache('data')->set($cid, $data, REQUEST_TIME + TMGMT_MYGENGO_COMMENTS_CACHE_EXPIRE);
      \Drupal::cache('data')->set($cid, $data, \Drupal::time()->getRequestTime() + TMGMT_MYGENGO_COMMENTS_CACHE_EXPIRE);
      return $data;
    }
    catch (TMGMTException $e) {
      drupal_set_message($e->getMessage(), 'error');
      $this->messenger()->addError($e->getMessage());
      watchdog_exception('tmgmt_mygengo', $e);
      return array();
    }
+2 −2
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ class MyGengoTranslator extends TranslatorPluginBase implements ContainerFactory
    }
    return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
      '@translator' => $translator->label(),
      ':configured' => $translator->url()
      ':configured' => $translator->toUrl()->toString(),
    ]));
  }

@@ -489,7 +489,7 @@ class MyGengoTranslator extends TranslatorPluginBase implements ContainerFactory
      }
      catch (TMGMTException $e) {
        watchdog_exception('tmgmt_mygengo', $e);
        drupal_set_message($e->getMessage(), 'error');
        $this->messenger()->addError($e->getMessage());
        continue;
      }
    }
Loading