You are here

function isotope_library_info_alter in Isotope (with Masonry and Packery) 8

Implements hook_library_info_alter().

File

./isotope.module, line 58
Isotope module.

Code

function isotope_library_info_alter(&$libraries, $extension) {

  // Optionally use the Libraries module to determine our library paths.
  if ($extension == 'isotope' && \Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $search_for = [
      'imagesloaded' => 'imagesloaded.pkgd.min.js',
      'isotope-cells-by-column' => 'cells-by-column.js',
      'isotope-cells-by-row' => 'cells-by-row.js',
      'isotope-fit-columns' => 'fit-columns.js',
      'isotope-horizontal' => 'horizontal.js',
      'isotope-layout' => 'isotope.pkgd.min.js',
      'isotope-masonry-horizontal' => 'masonry-horizontal.js',
      'packery' => 'packery.pkgd.min.js',
    ];
    foreach ($search_for as $lib_name => $lib_file) {

      // $discovery = new \Drupal\libraries\ExternalLibrary\Definition\ChainDefinitionDiscovery();
      // try {
      //   $lib = $discovery->getDefinition($lib_name);
      // }
      // catch (Drupal\libraries\ExternalLibrary\Exception\LibraryDefinitionNotFoundException $e) {}
      // @TODO: libraries_get_path() is deprecated. Waiting for best practice to emerge as libraries module matures.
      $local_file = libraries_get_path($lib_name) . '/' . $lib_file;
      if (file_exists($local_file)) {
        $file_description = preg_match('/\\.min\\./', $local_file) ? [
          'minified' => 'true',
        ] : [];
        $libraries[$lib_name]['js'] = [
          '/' . $local_file => $file_description,
        ];
      }
    }
  }
}