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

modules/charts_billboard/charts_billboard.install
<?php

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

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

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

      if (!$library_path) {
        if ($cdn) {
          $requirements['charts_billboard_js'] = [
            'title' => t('Billboard.js Library'),
            'value' => t('Available through a CDN'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You are using the Billboard.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_billboard for instructions to install the library.'),
          ];
        }
        else {
          $requirements['charts_billboard_js'] = [
            'title' => t('Billboard.js Library'),
            'value' => t('Not Installed'),
            'severity' => REQUIREMENT_ERROR,
            'description' => t('You are missing the Billboard.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_billboard for instructions to install the library.'),
          ];
        }
      }
      else {
        // If the library directory contains a demo directory, warn.
        if (file_exists($library_path . '/src')) {
          $requirements['charts_billboard_js'] = [
            'title' => t('Billboard.js Library'),
            'value' => t('Installed'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You have installed the Billboard.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_billboard.libraries.yml. We have included a suggested post-install/post-update script in the README file.'),
          ];
        }
        else {
          $requirements['charts_billboard_js'] = [
            'title' => t('Billboard.js Library'),
            'value' => t('Installed'),
            'severity' => REQUIREMENT_OK,
            'description' => t('You have installed the Billboard.js library in your Drupal installation directory.'),
          ];
        }
      }
      break;
  }

  return $requirements;
}

/**
 * Get the location of the Billboard.js library.
 *
 * @return string
 *   The location of the library, or FALSE if the library isn't installed.
 */
function charts_billboard_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 . '/billboard/dist/billboard.min.js') || file_exists($dir . '/billboard/dist/billboard.js')) {
      return $dir . '/billboard';
    }
  }

  return FALSE;
}

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

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