Commit e202d37e authored by Remco Hoeneveld's avatar Remco Hoeneveld Committed by Adriano Pulz
Browse files

Issue #3247672: Fixed for drupal 9 and compatibility issues with eu.

parent 60c26e25
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -25,6 +25,6 @@
  "license": "GPL-2.0-or-later",
  "minimum-stability": "dev",
  "require": {
    "zohocrm/php-sdk": "2.0.1"
    "zohocrm/php-sdk-archive": "2.0.6"
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -61,11 +61,11 @@ class ZohoCRMIntegrationRevoke extends ControllerBase {
    }
    catch (GuzzleException $e) {
      $this->messenger->addMessage($this->t('We have problems trying revoke your token.'), 'error');
      // TODO: Log error message.
      // @todo Log error message.
    }
    catch (ZohoOAuthException $e) {
      $this->messenger->addMessage($this->t('We have problems trying revoke your token.'), 'error');
      // TODO: Log error message.
      // @todo Log error message.
    }

    return $this->redirect('zoho_crm_integration.settings');
+29 −13
Original line number Diff line number Diff line
@@ -3,10 +3,11 @@
namespace Drupal\zoho_crm_integration\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\zoho_crm_integration\Service\ZohoCRMAuthService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Module settings page controller.
@@ -16,19 +17,26 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
  /**
   * The Zoho CRM Auth service.
   *
   * @var Drupal\zoho_crm_integration\Service\ZohoCRMAuthService
   * @var \Drupal\zoho_crm_integration\Service\ZohoCRMAuthService
   */
  protected $authService;

  /**
   * The Drupal messenger service.
   *
   * @var Drupal\Core\Messenger\Messenger
   * @var \Drupal\Core\Messenger\Messenger
   */
  protected $messenger;

  /**
   * The Drupal URL Generator service.
   * Symfony\Component\HttpFoundation\Request definition.
   *
   * @var \Symfony\Component\HttpFoundation\Request|null
   */
  protected $currentRequest;

  /**
   * Drupal\Core\Routing\UrlGeneratorInterface definition.
   *
   * @var \Drupal\Core\Routing\UrlGeneratorInterface
   */
@@ -41,12 +49,15 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
   *   The module handler service.
   * @param \Drupal\Core\Messenger\Messenger $messenger
   *   The messenger service.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request
   *   The request stack.
   * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
   *   The UrlGeneratorInterface service.
   *   The url generator.
   */
  public function __construct(ZohoCRMAuthService $auth_service, Messenger $messenger, UrlGeneratorInterface $url_generator) {
  public function __construct(ZohoCRMAuthService $auth_service, Messenger $messenger, RequestStack $request, UrlGeneratorInterface $url_generator) {
    $this->authService = $auth_service;
    $this->messenger = $messenger;
    $this->currentRequest = $request->getCurrentRequest();
    $this->urlGenerator = $url_generator;
  }

@@ -57,14 +68,18 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
    return new static(
      $container->get('zoho_crm_integration.auth'),
      $container->get('messenger'),
      $container->get('request_stack'),
      $container->get('url_generator')
    );
  }

  /**
   * Returns a render-able array for a test page.
   * Returns a render-able array for a settings page.
   *
   * @return array
   *   Returns the render array.
   */
  public function content() {
  public function content(): array {
    if (!$this->authService->checkSdkClass()) {
      $this->messenger->addMessage($this->t('You have not installed the Zoho SDK.'), 'error');

@@ -84,8 +99,11 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
    $redirect_link = $this->authService->redirectUrl;

    // Check for redirect param code.
    if (!$status && isset($_GET['code'])) {
      $access = $this->authService->generateAccessToken($_GET['code']);
    if (
      !$status &&
      $this->currentRequest->query->has('code')
    ) {
      $access = $this->authService->generateAccessToken($this->currentRequest->query->get('code'));
      if ($access) {
        $this->messenger->addMessage($this->t('You get Authorization on your Zoho CRM.'), 'status');
      }
@@ -98,7 +116,7 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
      $this->messenger->addMessage($this->t('You are not connected yet. Add your Zoho Client configurations below to be able to get you Authorization.'), 'warning');
    }

    $build = [
    return [
      '#theme' => 'zoho_crm_integration__settings_page',
      '#form' => $form,
      '#auth_url' => $auth_url,
@@ -112,8 +130,6 @@ class ZohoCRMIntegrationSettingsPage extends ControllerBase {
        ],
      ],
    ];

    return $build;
  }

}
+31 −10
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ use Drupal\Component\Utility\Unicode;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class ZohoCRMIntegrationForm.
 * The Zoho CRM Integration Form.
 *
 * @package Drupal\zoho_crm_integration\Form
 */
@@ -23,6 +23,27 @@ class ZohoCRMIntegrationForm extends ConfigFormBase {
   */
  const SETTINGS = 'zoho_crm_integration.settings';

  /**
   * ZohoCRMIntegrationScopesService definition.
   *
   * @var \Drupal\zoho_crm_integration\Service\ZohoCRMIntegrationScopesService
   */
  protected $scopesService;

  /**
   * All the scopes.
   *
   * @var array
   */
  protected $allScopes;

  /**
   * The flattened scopes.
   *
   * @var array
   */
  protected $flattenedScopes;

  /**
   * ZohoCRMIntegrationForm constructor.
   *
@@ -34,9 +55,9 @@ class ZohoCRMIntegrationForm extends ConfigFormBase {
  public function __construct(ConfigFactoryInterface $config_factory, ZohoCRMIntegrationScopesService $scopes_service) {
    parent::__construct($config_factory);

    $this->scopes_service = $scopes_service;
    $this->all_scopes = $scopes_service->getAllScopes();
    $this->flattened_scopes = $scopes_service->getFlattenedScopes();
    $this->scopesService = $scopes_service;
    $this->allScopes = $scopes_service->getAllScopes();
    $this->flattenedScopes = $scopes_service->getFlattenedScopes();
  }

  /**
@@ -110,10 +131,10 @@ class ZohoCRMIntegrationForm extends ConfigFormBase {
      '#title' => $this->t('Choose your Zoho Domain'),
      '#default_value' => $config->get('zoho_domain'),
      '#options' => [
        'https://accounts.zoho.com' => '.COM (Default)',
        'https://accounts.zoho.eu' => '.EU',
        'https://accounts.zoho.com.cn' => '.CN',
        'https://accounts.zoho.in' => '.IN',
        'com' => $this->t('.COM (Default)'),
        'eu' => $this->t('.EU'),
        'cn' => $this->t('.CN'),
        'in' => $this->t('.IN'),
      ],
      '#required' => TRUE,
    ];
@@ -125,7 +146,7 @@ class ZohoCRMIntegrationForm extends ConfigFormBase {
    ];

    // Retrieve scopes service.
    foreach ($this->all_scopes as $group => $scopes) {
    foreach ($this->allScopes as $group => $scopes) {
      // Scope group title.
      $form['container'][$group] = [
        '#type' => 'container',
@@ -168,7 +189,7 @@ class ZohoCRMIntegrationForm extends ConfigFormBase {
    ];

    // Scopes set in checkbox elements.
    $scope_configs = $this->scopes_service->getFlattenedScopes();
    $scope_configs = $this->scopesService->getFlattenedScopes();

    // Merge  both text and checkbox configs.
    $all_configs = array_merge($text_configs, $scope_configs);
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
namespace Drupal\zoho_crm_integration\Service;

/**
 * Interface ZohoCRMAuthInterface.
 * The Zoho CRM Auth Interface.
 */
interface ZohoCRMAuthInterface {

Loading