- 🇪🇸Spain cesarmsfelipe
Hi everyone,
I encountered an issue where both the select2 and webform Drupal 9 modules required the same JavaScript library (jquery.select2), but it was only being fetched and stored for the webform module in web/libraries/jquery.select2. The select2 module, however, was expecting this library to be in web/libraries/select2, which led to a dependency resolution problem.
To solve this, I implemented a solution using a symbolic link, created by a script executed via Composer's event hooks. This approach ensures that the select2 module can correctly locate and use the jquery.select2 library without needing to duplicate the library files.
Here's the script that creates the symbolic link (scripts/fix_select2_dependency.php):
<?php
$source = __DIR__ . '/../web/libraries/jquery.select2';
$destination = __DIR__ . '/../web/libraries/select2';// Check if the destination directory exists, create it if it doesn't
if (!file_exists(dirname($destination))) {
mkdir(dirname($destination), 0755, true);
}// Create a symbolic link if it does not already exist
if (!is_link($destination)) {
symlink($source, $destination);
echo "Symbolic link created: $destination -> $source\n";
}And these are the modifications to composer.json to invoke the script after install and update events:
"scripts": {
"post-install-cmd": [
"php scripts/fix_select2_dependency.php"
],
"post-update-cmd": [
"php scripts/fix_select2_dependency.php"
]
}I hope this solution helps anyone facing a similar issue. Feel free to adjust the script paths according to your project's directory structure.