You are here

function charts_chartjs_find_library in Charts 5.0.x

Get the location of the Chart.js library.

Return value

string The location of the library, or FALSE if the library isn't installed.

1 call to charts_chartjs_find_library()
charts_chartjs_requirements in modules/charts_chartjs/charts_chartjs.install
Implements hook_requirements().

File

modules/charts_chartjs/charts_chartjs.install, line 45
Installation and uninstallation functions.

Code

function charts_chartjs_find_library() {

  // The following logic is taken from libraries_get_libraries()
  $searchdir = [];

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

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

  // Also search sites/<domain>/*.
  $searchdir[] = \Drupal::service('site.path') . '/libraries';
  foreach ($searchdir as $dir) {
    if (file_exists($dir . '/chartjs/dist/chart.js')) {
      return $dir . '/chartjs';
    }
  }
  return FALSE;
}