Use external libraries

Submitted by kplatis on

There are Drupal modules that use external PHP libraries and in order to work properly must be installed using composer. CERN Drupal infrastructure doesn't support composer so we need a workaround to make the module aware of these libraries and use them.

In most of the cases the Ludwig Drupal module provides the solution to this problem. The module is already available in CERN Drupal infrastructure and there is no need to install it. You can enable it anytime.

Using Ludwig

Let's say that you want to install the module Feeds extensible parsers in order to be able to export content from your website or import content in JSON format. This module requires the external libraries JsonPath, JMESPath and QueryPath in order to work. Install the Feeds extensible parsers module and then mount the filesystem of your website https://<your-website-name>

Go to the module's folder "modules/feeds_ex" and create a file called ludwig.json Open the file with an editor and paste the following text:

    "require": {
        "mtdowling/jmespath.php": {
            "version": "v2.4.0",
            "url": ""
        "peekmo/jsonpath": {
            "version": "v1.1.0",
            "url": ""
        "querypath/QueryPath": {
            "version": "v3.0.5",
            "url": ""

Before we continue let me explain a bit the structure of this file. You will notice that all three libraries are listed along with their versions and their paths from where you can download them. After the "require:" it follows the field with the name of the library. You don't have to write it exactly as the example. You can write "jmespath" instead of "mtdowling/jmespath.php". Next you see the version of the library followed by the URL.

Once you construct the ludwig.json file with the libraries that you need, go to https://<your-website-name> and you will see a list with the packages you need to install. Each one will have a link to download the files from and the path where you have to place them within your module (usually modules/feeds_ex/lib/jmespath etc.). After you download and installed successfully the libraries clear the cache and their status should change from "missing" to "installed".

After this your module should be working properly.

Without Ludwig

There are modules that require external libraries and don't support Ludwig. There is a workaround to make this work. You can reference directly the necessary libraries into the module's code. Some modules will tell you exactly what you need to do, so you should always check the module's page for information. If there are no instructions on its page then search in Google for "<module's name> ludwig support". You will definitely find some articles referring how to make this module work with Ludwig or how to reference the library in case Ludwig doesn't work.

For example, the Swift Mailer Drupal module requires the Swiftmailer library. Download the Swiftmailer library and put it into the module's folder under the folder lib. Then open the file swiftmailer.install and add at the beginning of the file the following line:


Save the file and then do the same with the file swiftmailer.install. Now the module will detect the Swiftmailer library and will work properly.