Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / library_info_alter.twig
1 /**
2  * Implements hook_library_info_alter().
3  */
4 function {{ machine_name }}_library_info_alter(&$libraries, $extension) {
5   // Update Farbtastic to version 2.0.
6   if ($extension == 'core' && isset($libraries['jquery.farbtastic'])) {
7     // Verify existing version is older than the one we are updating to.
8     if (version_compare($libraries['jquery.farbtastic']['version'], '2.0', '<')) {
9       // Update the existing Farbtastic to version 2.0.
10       $libraries['jquery.farbtastic']['version'] = '2.0';
11       // To accurately replace library files, the order of files and the options
12       // of each file have to be retained; e.g., like this:
13       $old_path = 'assets/vendor/farbtastic';
14       // Since the replaced library files are no longer located in a directory
15       // relative to the original extension, specify an absolute path (relative
16       // to DRUPAL_ROOT / base_path()) to the new location.
17       $new_path = '/' . drupal_get_path('module', 'farbtastic_update') . '/js';
18       $new_js = [];
19       $replacements = [
20         $old_path . '/farbtastic.js' => $new_path . '/farbtastic-2.0.js',
21       ];
22       foreach ($libraries['jquery.farbtastic']['js'] as $source => $options) {
23         if (isset($replacements[$source])) {
24           $new_js[$replacements[$source]] = $options;
25         }
26         else {
27           $new_js[$source] = $options;
28         }
29       }
30       $libraries['jquery.farbtastic']['js'] = $new_js;
31     }
32   }
33 }