fortnox-8.x-1.x-dev/fortnox.module

fortnox.module
<?php

/**
 * @file
 * Contains fortnox.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\fortnox_credentials\Entity\CredentialsInterface;

/**
 * Implements hook_help().
 */
function fortnox_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the fortnox module.
    case 'help.page.fortnox':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Fortnox API integration.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave().
 */
function fortnox_credentials_presave(CredentialsInterface $entity) {
  /* @var $fortnox_client \Drupal\fortnox\Services\FortnoxClientInterface */
  $fortnox_client = \Drupal::service('fortnox.client');
  $response = !$entity->isNew() ? $fortnox_client->checkIfIntegrationIsEnabled() : FALSE;
  if ($response == FALSE) {
    $access_token = $fortnox_client->enableIntegration($entity->getClientSecret(), $entity->getApiCode());
    if (!empty($access_token)) {
      $entity->setAccessToken($access_token);
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc