cloudinary-8.x-1.x-dev/modules/cloudinary_sdk/cloudinary_sdk.install

modules/cloudinary_sdk/cloudinary_sdk.install
<?php

/**
 * @file
 * Provides installation functions for cloudinary_sdk module.
 */

use Drupal\Core\Url;
use Drupal\cloudinary_sdk\CloudinarySdkConstantsInterface;

/**
 * Implements hook_uninstall().
 */
function cloudinary_sdk_uninstall() {
  \Drupal::configFactory()->getEditable('cloudinary_sdk.settings')->delete();
}

/**
 * Implements hook_requirements().
 */
function cloudinary_sdk_requirements($phase) {
  $requirements = [];

  // None of these requirements are relevant outside of runtime.
  if ($phase != 'runtime') {
    return $requirements;
  }

  list($status, $version, $error_message) = cloudinary_sdk_check(TRUE);
  $r = [
    'severity' => REQUIREMENT_OK,
    'title' => t('Cloudinary'),
    'value' => $version,
  ];

  if ($status == CloudinarySdkConstantsInterface::CLOUDINARY_SDK_NOT_LOADED) {
    $r['severity'] = REQUIREMENT_ERROR;
    $r['value'] = t('Failed to load the Cloudinary SDK.');
    if ($error_message) {
      $r['value'] .= ' ' . $error_message;
    }
    $r['description'] = t('Please make sure the Cloudinary SDK library is installed in the libraries directory.');
  }
  elseif ($status == CloudinarySdkConstantsInterface::CLOUDINARY_SDK_OLD_VERSION) {
    $r['severity'] = REQUIREMENT_ERROR;
    $r['description'] = t(
      'Please make sure the Cloudinary SDK library installed is @version or greater. Current version is @current_version.',
      [
        '@version' => CloudinarySdkConstantsInterface::CLOUDINARY_SDK_MINIMUM_VERSION,
        '@current_version' => $version,
      ]
    );
  }
  else {
    // Ensure that the 3 required fields have been set.
    // Cloud name, API key, API secret.
    $config = cloudinary_sdk_config_load();
    if (empty($config)) {
      $r['severity'] = REQUIREMENT_WARNING;
      // Add link to configuration form.
      $url = Url::fromRoute('cloudinary_sdk.settings')->toString(TRUE)->getGeneratedUrl();
      $r['description'] = t("The required cloud name, API key and API secret of Cloudinary hasn't been set. <a href=':url'>Configure</a>", [
        ':url' => $url,
      ]);
    }
  }

  $requirements['cloudinary_sdk'] = $r;

  return $requirements;
}

/**
 * Set default value for cloudinary_sdk_upload_prefix.
 */
function cloudinary_sdk_update_8001() {
  $config = \Drupal::configFactory()->getEditable('cloudinary_sdk.settings');
  $config->set('cloudinary_sdk_upload_prefix', 'https://api.cloudinary.com');
  $config->save();
}

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

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