You are here

function toc_js_library_info_alter in Toc.js 2.0.x

Implements hook_library_info_alter().

This override is necessary to allow library detection inside the /dist folder allowing an installation via npm asset-packagist.

@todo: simplified when [#3093289] lands to keep dist folder only.

See also

[#3089718]

File

./toc_js.module, line 434
Contains toc_js.module.

Code

function toc_js_library_info_alter(&$libraries, $extension) {

  // Alter toc_js/tocjs library if necessary.
  if ($extension === 'toc_js' && isset($libraries['tocjs'])) {

    // Verify existence of /dist folder file.
    if (file_exists(DRUPAL_ROOT . '/libraries/toc/dist/toc.min.js')) {

      // Update the existing file path.
      $libraries['tocjs']['js'] = [
        '/libraries/toc/dist/toc.min.js' => [
          'minified' => TRUE,
        ],
      ];
    }
  }
}