commercetools-8.x-1.2-alpha1/commercetools.module

commercetools.module
<?php

/**
 * @file
 * Defines the commercetools module hooks.
 */

use Drupal\commercetools\CommercetoolsCron;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageInterface;

/**
 * Implements hook_theme().
 */
function commercetools_theme() {
  return [
    'commercetools_summary' => [
      'variables' => [
        'project_settings' => [
          'key' => '',
          'name' => '',
          'countries' => [],
          'currencies' => [],
          'languages' => [],
          'customer_groups' => [],
        ],
      ],
      'template' => 'commercetools-summary',
    ],
  ];
}

/**
 * Calls the OOP processor of the cron hook.
 *
 * Implements hook_cron().
 */
function commercetools_cron() {
  \Drupal::service(CommercetoolsCron::class)->executeCron();
}

/**
 * Handles localization updates when a new language is added.
 *
 * Implements hook_ENTITY_insert().
 */
function commercetools_configurable_language_insert(ConfigurableLanguageInterface $language) {
  /** @var \Drupal\commercetools\CommercetoolsApiServiceInterface $ctApi */
  $ctApi = \Drupal::service('commercetools.api');
  /** @var \Drupal\commercetools\CommercetoolsLocalization $ctLocalization */
  $ctLocalization = \Drupal::service('commercetools.localization');
  $code = $language->getId();
  try {
    $info = $ctApi->getProjectInfo();
    $localeSettings = $ctLocalization->assortLanguageParameters($code, $info);
    $ctLocalization->saveLocaleSettings($code, $localeSettings);
  }
  catch (\Exception) {
    \Drupal::messenger()->addWarning('Unable to complete commercetools localization settings automatically. Visit <a href="@settings">commercetools Store settings</a> page.', [
      '@settings' => Url::fromRoute('commercetools.settings_store')->toString(),
    ]);
  }
}

/**
 * A workaround to allow the translation server to find the translation files.
 *
 * @param array $projects
 *   An array of projects.
 *
 * @see https://www.drupal.org/project/drupal/issues/3483087
 *
 * @todo Remove this hook when the issue is fixed.
 */
function commercetools_locale_translation_projects_alter(&$projects) {
  $moduleName = 'commercetools';
  $modulePath = \Drupal::service('module_handler')->getModule($moduleName)->getPath();
  $projects[$moduleName]['info']['interface translation server pattern'] =
    str_replace(
      'module://',
      $modulePath . '/',
      $projects[$moduleName]['info']['interface translation server pattern']
    );
}

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

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