--- /dev/null
+/**
+ * Implements hook_library_info_alter().
+ */
+function {{ machine_name }}_library_info_alter(&$libraries, $extension) {
+ // Update Farbtastic to version 2.0.
+ if ($extension == 'core' && isset($libraries['jquery.farbtastic'])) {
+ // Verify existing version is older than the one we are updating to.
+ if (version_compare($libraries['jquery.farbtastic']['version'], '2.0', '<')) {
+ // Update the existing Farbtastic to version 2.0.
+ $libraries['jquery.farbtastic']['version'] = '2.0';
+ // To accurately replace library files, the order of files and the options
+ // of each file have to be retained; e.g., like this:
+ $old_path = 'assets/vendor/farbtastic';
+ // Since the replaced library files are no longer located in a directory
+ // relative to the original extension, specify an absolute path (relative
+ // to DRUPAL_ROOT / base_path()) to the new location.
+ $new_path = '/' . drupal_get_path('module', 'farbtastic_update') . '/js';
+ $new_js = [];
+ $replacements = [
+ $old_path . '/farbtastic.js' => $new_path . '/farbtastic-2.0.js',
+ ];
+ foreach ($libraries['jquery.farbtastic']['js'] as $source => $options) {
+ if (isset($replacements[$source])) {
+ $new_js[$replacements[$source]] = $options;
+ }
+ else {
+ $new_js[$source] = $options;
+ }
+ }
+ $libraries['jquery.farbtastic']['js'] = $new_js;
+ }
+ }
+}