auto_alter-8.x-1.x-dev/modules/auto_alter_translate/auto_alter_translate.install

modules/auto_alter_translate/auto_alter_translate.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the auto_alter module.
 */

use Drupal\Core\Url;
use Drupal\auto_alter\AutoAlterCredentials;


/**
 * Implements hook_requirements().
 */
function auto_alter_translate_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $config = \Drupal::config('auto_alter_translate.settings');
    $credentials = new AutoAlterCredentials($config);
    $key = $credentials->getApikey();
    $url = $config->get('endpoint');

    if (!$key || !$url) {
      $requirements['auto_alter'] = [
        'title' => t('Automatic Alternative Text Translation'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('Microsoft Azure API key and Endpoint URL is not set and it is required for the module to work. Please set it up at the <a href=":settings">Image Automatic Alternative Text Translation settings page</a>.', [
          ':settings' => Url::fromRoute('auto_alter_translate.settings_form')->toString(),
        ]),
      ];
    }
  }
  return $requirements;
}

/**
 * Convert api key config to credential provider config.
 */
function auto_alter_translate_update_8401() {
  $config = \Drupal::configFactory()->getEditable('auto_alter_translate.settings');
  $key = $config->get('api_key');
  if ($key) {
    $config
      ->set('credential_provider', 'config')
      ->set('credentials.config.api_key', $key)
      ->clear('api_key')
      ->save(TRUE);
  }
}

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

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