Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Installation of Chosen 4.x recommends using the composer-merge-plugin. This change record recommend using path repositories: https://www.drupal.org/node/3069730
This plugin is also not compatible with Pantheon's Integrated Composer, which is where we noticed the issue: https://docs.pantheon.io/modules-known-issues#composer-merge-plugin
Proposed resolution
Update readme to recommend a path repository installation instead.
Thanks!
Issue fork chosen-3380068
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
vinmassaro CreditAttribution: vinmassaro commentedComment #3
vinmassaro CreditAttribution: vinmassaro commentedHere is a minimal example composer.json that installs the jjj/chosen library via path repository into
web/libraries/chosen
:Comment #4
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedHi!
Thanks!
I would say however that we should have both in the Readme.
As far as I understand the path repository is a manual process, and it was always possible in the past to do that manually.
But the disadvantage is that if the module changes the dependency, then the user might not update his own composer json manually, so that could be an issue.
While the merge plugin solved that issue by including the composer json from the module.
I think the deprecation happened when the merge plugin was not maintained temporarily, but now it is actively maintained actually.
But I think we should have this other option in the Readme anyways, because if merge plugin cannot be used on Pantheon, or there are other cases where it's not possible to be used then there should be this other way of managing it.
Comment #5
robbdavis CreditAttribution: robbdavis commentedThanks for this. Merge plugin stopped working on Pantheon and having the library disappear caused a few errors:
Getting the library back with the posted method fixed. So, yeah, this alternative method should be in the read me.
Comment #6
vinmassaro CreditAttribution: vinmassaro commented@robbdavis: thanks for confirming that is working. I will get a MR going with a readme change
Comment #7
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedSo basically what we can add to the README is the following:
Add the following entry to the root composer.json inside the "repositories" section:
Then you can run the following command to install the library to the right folder:
composer require jjj/chosen:2.2.1
Comment #8
iamdroid CreditAttribution: iamdroid at SystemSeed, 4D design commentedHi folks,
Thanks for the suggestions. From my end, I'd like to share an even simpler solution: since
jjj/chosen
is already available as a composer package there is no need to specify any repository for it. The only thing left to do is to specify the path to the libraries folder, like this:and then run
composer require jjj/chosen
Comment #9
coaston CreditAttribution: coaston commentedHi iamdroid,
I added jjj/chosen to composer json as described, however when I run
composer require jjj/chosen
composer downloaded libraries to vendor folder /jjj... And I can still see message in Drupal :You need to download the Chosen JavaScript file and extract the entire contents of the archive into the libraries/chosen directory in your Drupal installation directory.
I have also created libraries folder under web and moved downlaoded libary files there with no luck.
My steps:
1.composer require wikimedia/composer-merge-plugin
2.added to extra: "installer-paths": {
"web/libraries/{$name}": [ "jjj/chosen" ]
}
3.composer require jjj/chosen
4. added to extra:
5.composer require oomphinc/composer-installers-extender
6.composer require drupal/chosen
7.installed chosen
8.Refresh cache
9.You need to download the Chosen JavaScript file and extract the entire contents of the archive into the libraries/chosen directory in your Drupal installation directory.
What I am missing ?
Comment #10
coaston CreditAttribution: coaston commentedit seems this #comment-13324021helped, but not sure why I had to do that manually. When I tried before I used folder in root libraries/jjj/chosen but it has to be libraries/chosen only...
Comment #11
iamdroid CreditAttribution: iamdroid at SystemSeed, 4D design commentedHi @coaston,
I just double checked on a fresh Drupal installation, and you are right, it didn't work out of the box.
Initially, I tried it on the working project which already has
oomphinc/composer-installers-extender
plugin installed. Also, it somehow depends on theinstaller-types
option which seems unrelated at all but without it, nothing is working.So the complete setup looks like this:
composer require oomphinc/composer-installers-extender
composer.json
by addingcomposer require jjj/chosen
No need to do steps 1 and 4 from your list.
I have to admit that the full setup looks more or less like previously suggested options in terms of complexity unless you already using
composer-installers-extender
for managing npm and bower assets.And it is odd it is not working out of the box because it is what the official doc said https://www.drupal.org/docs/develop/using-composer/manage-dependencies#i...
Good luck.
Comment #12
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedThen we can have 3 options in the readme.
1. merge plugin - if possible, is the better approach as then it takes the version defined in the module.
but it is sometimes not possible or problematic so the other two options:
2. defining the repository as #7
3. defining the installer-paths as #11
Comment #13
sonfdI came here because I also ran into the issue with wikimedia/composer-merge-plugin on pantheon.
Thank you, @iamdroid - I can confirm that the steps recommended in #11 work. (I was already using oomphinc/composer-installers-extender so this was ideal.)
RE: @iamdroid's note:
This is required because the composer-installers-extender plugin only acts on packages with the types specified in
installer-types
. Withoutnpm-asset
listed there, the plugin will just ignore the package. Basically, oomphinc/composer-installers-extender will look at packages and install them them to directories other than vendor. It works by first checking if an installed package has a type that matches one of the types ininstaller-types
. It then checks if one of the paths defined ininstaller-paths
fits the package. It will use the first match found (i.e. the highest in the file) and the package will go to vendor if no installer path fits the installed package.Comment #14
bburch CreditAttribution: bburch commentedI tried a 3-4 different methods proposed in the Chosen doc., this thread, and issue #3102250.
Google's Bard LLM came up with the winning approach.
ALL HAIL THE ALGORITHM! And the person(s) whose work it copied.
1. Install the plugin:
composer require oomphinc/composer-installers-extender
2. Configure composer.json by adding the Chosen library under the "require" section:
"require": {
"jjj/chosen": "^2.2"
}
Add an extra section with an installer-paths configuration:
"extra": {
"installer-paths": {
"web/libraries/chosen": [
"jjj/chosen"
]
}
}
3. Run Composer update:
composer update
4. Enable the module:
Navigate to Administration > Extensions.
Search for "Chosen" and enable the "Chosen Library" module.
Comment #15
Prodigy CreditAttribution: Prodigy commentedCorrect there is a
composer.libraries.json
file which specifies the location of the chosen library, so you can get away with just:Then run:
composer require jjj/chosen
-----------------------
Although this works as well inside composer.json
Add the following entry to the root composer.json inside the "repositories" section:
Then you can run the following command to install the library to the right folder:
composer require jjj/chosen
Comment #16
butterwise CreditAttribution: butterwise as a volunteer commentedThank you, @Prodigy. Your second snippet got me back on track.
For those as novice as I when it comes to composer, note that you need to add
"jjj/chosen":
before the first left curly bracket.