charts-8.x-4.x-dev/modules/charts_c3/charts_c3.install

modules/charts_c3/charts_c3.install
<?php

/**
 * @file
 * Installation and uninstallation functions.
 */

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

  switch ($phase) {
    case 'runtime':
      $library_path = charts_c3_find_library();
      $config = \Drupal::config('charts.settings');
      $cdn = $config->get('advanced.requirements.cdn') ?? FALSE;

      if (!$library_path) {
        if ($cdn) {
          $requirements['charts_c3_js'] = [
            'title' => t('C3.js Library'),
            'value' => t('Available through a CDN'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You are using the C3.js library via a content delivery network. It is generally considered better practice to install the library files locally. Please see the README file inside charts_c3 for instructions to install the library.'),
          ];
        }
        else {
          $requirements['charts_c3_js'] = [
            'title' => t('C3.js Library'),
            'value' => t('Not Installed'),
            'severity' => REQUIREMENT_ERROR,
            'description' => t('You are missing the C3.js library in your Drupal installation directory and you have opted not to use a CDN. Please either enable use of the CDN in the Chart Settings under the Advanced tab or see the README file inside charts_c3 for instructions to install the library.'),
          ];
        }
      }
      else {
        // If the library directory contains a demo directory, warn.
        if (file_exists($library_path . '/src')) {
          $requirements['charts_c3_js'] = [
            'title' => t('C3.js Library'),
            'value' => t('Installed'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You have installed the C3.js library in your Drupal installation directory, but it contains additional files that are not required and may be harmful. Please delete everything except the files listed in charts_c3.libraries.yml. We have included a suggested post-install/post-update script in the README file.'),
          ];
        }
        else {
          $requirements['charts_c3_js'] = [
            'title' => t('C3.js Library'),
            'value' => t('Installed'),
            'severity' => REQUIREMENT_OK,
            'description' => t('You have installed the C3.js library in your Drupal installation directory.'),
          ];
        }
      }
      break;
  }

  return $requirements;
}

/**
 * Get the location of the C3.js library.
 *
 * @return string
 *   The location of the library, or FALSE if the library isn't installed.
 */
function charts_c3_find_library() {
  // The following logic is taken from libraries_get_libraries()
  $search_dir = [];

  // Similar to 'modules' and 'themes' directories inside an installation
  // profile, installation profiles may want to place libraries into a
  // 'libraries' directory.
  $search_dir[] = 'profiles/' . \Drupal::installProfile() . '/libraries';

  // Always search libraries.
  $search_dir[] = 'libraries';

  // Also search sites/<domain>/*.
  $container = \Drupal::getContainer();
  $site_path = $container->getParameter('site.path');
  $site_path = explode('/', $site_path);
  $site_name = $site_path[1];
  $search_dir[] = $site_name . '/libraries';

  foreach ($search_dir as $dir) {
    if (file_exists($dir . '/c3/c3.min.js') || file_exists($dir . '/c3/c3.js')) {
      return $dir . '/c3';
    }
  }

  return FALSE;
}

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

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