Martyn
Martyn

Reputation: 6383

How to instal modules with Drupal 8 and Composer?

I installed Drupal 8 via composer with:

composer create-project drupal-composer/drupal-project:8.x-dev my_site --stability dev --no-interaction

This downloaded all the files and run composer install. According to this tutorial - https://www.drupal.org/node/2718229 - doing so this way will also configure composer.json to allow installation of modules, themes etc too via composer. Nice

However, I'm trying to install a new module:

$ composer require drupal/codesnippet
Using version ^1.6 for drupal/codesnippet
./composer.json has been updated
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing drupal/codesnippet (1.6.0)
    Downloading: 100%         

Writing lock file
Generating autoload files
> DrupalProject\composer\ScriptHandler::createRequiredFiles

However, when I go to Admin Bar > Extend > Install new module, I can search for the module and it says it's not installed yet. If I try to enable/install it from there it tells me I need to download and copy to the /libraries directory:

Before you can use the CKEditor CodeSnippet module, you need to download the codesnippet plugin from ckeditor.com and place it in /libraries/codesnippet. Check the README.txt for more information. Get the plugin here. (Currently using CodeSnippet version Plugin not detected) 

Are these two completely different methods? How can I complete the installation with composer of this module?

Upvotes: 0

Views: 1207

Answers (2)

Marcel Cozma
Marcel Cozma

Reputation: 4489

Martyn, I guess you are confusing two different things into the same one: the drupal module and the external library required by the module.
The Drupal module codesnippet (https://www.drupal.org/project/codesnippet) is just a drupal integration module for the CKeditor addon with the same name, which you can download it (http://download.ckeditor.com/codesnippet/releases/codesnippet_4.6.2.zip) and place it in the drupal webroot /libraries folder manually (in your case my_site/web/libraries/ to be more specific - you have to create it if does not exist already).

Then you should be able to enable the drupal module.

PS: You could also add the library requirement in the composer.json library manually, which might be just a bit more complicated for beginners, because you also have to manually specify other things like a repository type, url and installer-paths for the extra external library that you need , but might be easier in the long run to deploy new Drupal8 installations with the same requirements just with a proper main composer.json file, without the need to go and manually download external libraries. There is a similar comment of mine(user zet) that you could read on this drupal dropzonejs module issue https://www.drupal.org/node/2853274

Upvotes: 0

Karl Buys
Karl Buys

Reputation: 449

Composer is a dependency manager, and whether or not third-party dependencies are included depends on how the module author managed their dependencies in the first place.

You aren't going to be able to complete the install via Composer alone, if a specific dependency isn't present on the repository that Composer downloads its packages from.

You're going to have to download the CKEditor CodeSnippet module from ckeditor.com. Composer can't manage that dependency for you, because that CKEditor plugin isn't a Composer package.

You can download it here: http://ckeditor.com/addon/codesnippet

Upvotes: 0

Related Questions