Commit 6286cce6 authored by Nia Kathoni's avatar Nia Kathoni Committed by Daniel Cothran
Browse files

Issue #3286450 by nikathone, andileco: Automated Drupal 10 compatibility fixes

parent 60e26ff0
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -207,15 +207,27 @@ function _charts_library_info_alter_recursive(array &$library, array $cdn) {
 */
function _charts_library_check_source_exists(string $source) {
  $source = rtrim($source, '/');

  // @todo refactor the if statement below when dropping support for drupal 8.
  if (version_compare(\Drupal::VERSION, '9.0', '<')) {
    $app_root = \Drupal::service('app.root');
    $site_path = \Drupal::service('site.path');
  }
  else {
    $container = \Drupal::getContainer();
    $app_root = $container->getParameter('app.root');
    $site_path = $container->getParameter('site.path');
  }

  // The following logic is taken from libraries_get_libraries()
  $search_dir = [];
  $search_dir[] = \Drupal::service('app.root');
  $search_dir[] = $app_root;
  // 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();
  // Also search sites/<domain>/*.
  $search_dir[] = \Drupal::service('site.path');
  $search_dir[] = $site_path;

  foreach ($search_dir as $dir) {
    if (file_exists($dir . $source) || file_exists($dir . $source)) {