Lifted to PSR-4, Plugin gets recognized. Remark: tmgmt core neeeds a 'tmgmt.translator_delete' route for the plugin to work.

Got stuck with Guzzle at the GetToken Post request. Error message:

No method can handle the grant_type config key

Any hint?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cgalli’s picture

cgalli’s picture

Status: Active » Needs review
Berdir’s picture

Status: Needs review » Needs work

Patch is empty

cgalli’s picture

Status: Needs work » Needs review
FileSize
30.45 KB

Here it comes....

miro_dietiker’s picture

Status: Needs review » Needs work

Hello! Looks awesome.
A few minor corrections to consider... And one general question about the status of the port.

  1. +++ b/src/MicrosoftTranslatorUi.php
    @@ -0,0 +1,39 @@
    +    $form['clientid'] = array(
    ...
    +      '#default_value' => $translator->getSetting('clientid'),
    ...
    +    $form['clientsecret'] = array(
    ...
    +      '#default_value' => $translator->getSetting('clientsecret'),
    
    +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,321 @@
    +      'client_id' => $clientID,
    +      'client_secret' => $clientSecret,
    

    I think we should properly name them:
    clientid => client_id
    clientsecret => client_secret

  2. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,321 @@
    +  /**
    +   * Overrides TMGMTDefaultTranslatorPluginController::canTranslate().
    +   */
    +  public function canTranslate(Translator $translator, Job $job) {
    ...
    +  /**
    +   * Implements TMGMTTranslatorPluginControllerInterface::requestTranslation().
    +   */
    +  public function requestTranslation(Job $job) {
    

    Should be only {@inheritdoc}... and more similar locations.

  3. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,321 @@
    +   * Execute a request against the Microsoft API.
    

    Executes, not Execute.

  4. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,321 @@
    +   * Get the access token.
    

    Gets not Get.

  5. +++ b/src/Tests/MicrosoftTest.php
    @@ -0,0 +1,100 @@
    +      'url' => url('tmgmt_microsoft_mock/v2/Http.svc', array('absolute' => TRUE)),
    

    I can't see where this mocking is provided. I fear this test can not work without it? Did you run these tests?

  6. +++ b/src/Tests/MicrosoftTest.php
    @@ -0,0 +1,100 @@
    +    $this->assertFalse($job->isTranslatable(), 'Check if the translator is not
    +                       available at this point because we did not define the API
    +                       parameters.');
    

    Wrong indentation.

miro_dietiker’s picture

Title: Update Translator Plugin to D8 Dev » Port Translator Plugin to Drupal 8

Some more common title for port issues. :-)

cgalli’s picture

FileSize
1.39 KB

Correction: wrong issue :-) this belongs to #2381149: Catchup with D8 core, remove unused code

little corrections:
- remove $temp
- repalces deprecated drupalt_strlen()

cgalli’s picture

Updated to Drupal 8 Dev

Working with tests

cgalli’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Status: Needs review » Needs work

Nice update. Just some smaller fixings needed. :-)

  1. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +    // Backwards compatibility for the old api key.
    +    if ($translator->getSetting('api')) {
    +      return TRUE;
    +    }
    

    I think we should drop backwards compatibility for old settings / microsoft api keys.

  2. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +      // If one of the texts in this job exceeds the max character count the job
    +      // can't be translated.
    

    Wrapping 80 chars.

  3. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +  public function getSupportedRemoteLanguages(Translator $translator) {
    +    $languages = array();
    +    // Prevent access if the translator isn't configured yet.
    +    if (!$translator->getSetting('clientid')) {
    +      return $languages;
    

    This is a TMGMT API problem. Here we should throw an exception. Otherwise we risk the reply (no languages supported) end up cached.

  4. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +      drupal_set_message($e->getMessage(), 'error');
    

    Possibly prepend the exception message here to make the origin of the message clear.

  5. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +      unset($languages[$source_language]);
    

    A comment here would be nice... "Remove source language from targets."

  6. +++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
    @@ -0,0 +1,326 @@
    +    // The new Api uses 2 new parameters and access token.
    

    Api => API

  7. +++ b/src/Tests/MicrosoftTest.php
    @@ -0,0 +1,94 @@
    + * Test cases for the microsoft translator module.
    ...
    + * Basic tests for the microsoft translator.
    ...
    +      'description' => 'Tests the microsoft translator plugin integration.',
    

    microsoft => Microsoft.

  8. +++ b/src/Tests/MicrosoftTest.php
    @@ -0,0 +1,94 @@
    +    // Save a wrong api key.
    ...
    +    // Save a correct api key.
    

    api => API

  9. +++ b/tmgmt_microsoft_test/src/Controller/MicrosoftTranslatorTestController.php
    @@ -0,0 +1,116 @@
    +   * Helper to trigger mok response error.
    

    mok => mock

  10. +++ b/tmgmt_microsoft_test/src/Controller/MicrosoftTranslatorTestController.php
    @@ -0,0 +1,116 @@
    +    else {
    +
    

    Useless empty line.

  11. +++ b/tmgmt_microsoft_test/src/Controller/MicrosoftTranslatorTestController.php
    @@ -0,0 +1,116 @@
    +      $response = new Response($response_str, '200');
    +      return $response;
    +    }
    +    else {
    +      $response = new response('400', array('status' => 'Invalid token'), 'Bad request');
    

    response => Response and plz check the argument sequence... (the second can not work... so we don't even test it ever?)

Hint: We were a bit confused about the XML / JSON mix here. JSON seems needed for the service token and XML is for all the actual services payload work (languages, translate body).

cgalli’s picture

Status: Needs work » Needs review
FileSize
18.52 KB
3.81 KB

Improved according to #10

miro_dietiker’s picture

Verry nice. One final thing from my side.

+++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
@@ -237,28 +239,30 @@ class MicrosoftTranslator extends TranslatorPluginBase implements ContainerFacto
+    $request_url = Url::fromUri($url)->toString();

+++ b/src/Tests/MicrosoftTest.php
@@ -31,28 +32,21 @@ class MicrosoftTest extends TMGMTTestBase {
+      'url' => URL::fromUri('base://tmgmt_microsoft_mock/v2/Http.svc', array('absolute' => TRUE))->toString(),

This leads to double fromUri wrapping.

miro_dietiker’s picture

OK fixed some stuff...

Renamed clientid to client_id... and similar.
Added missing @file headers.
Added some type hints.
Consistently use TMGMTException instead of Exception.

miro_dietiker’s picture

Status: Needs review » Fixed

Additionally reverted one wrong type hint fix (create() array argument).

Yay! Committed, pushed.

  • miro_dietiker committed d597d2d on 8.x-1.x authored by cgalli
    Issue #2372047 by cgalli, miro_dietiker: Port Translator Plugin to...

The last submitted patch, 4: update_to_d8dev_2372047_4.patch, failed testing.

The last submitted patch, 7: google_d8_2372047_7.patch, failed testing.

The last submitted patch, 11: port_translator_plugin_to_d8_2372047_11.patch, failed testing.

The last submitted patch, 8: port_translator_plugin_to_d8_2372047_8.patch, failed testing.

Status: Fixed » Needs work

The last submitted patch, 13: tmgmt_microsoft_2372047_13.patch, failed testing.

Berdir’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.