I have zero command line access to a remotely hosted drupal site so I'm unable to run composer. My custom module requires the ryanwinchester/hubspot-php package. Is there any way I can manually add this library to my module without having to run composer? I'm willing to do any workaround no matter how dirty or frowned upon the technique is. I am able to run composer locally so I can at least produce a vendor folder with the autoload.php included.

Could I manually include the autoload.php in my module? Is this something I could just require in every class that uses the package?


It's quite common that production sites are unable to run composer. Even if command line access is available the site code is read-only, so composer would be unable to make any changes. Either developers have to use composer locally and upload all modules and vendor files to the production environment, or a build system takes care of that task.

Your Drupal site will only have one vendors folder and autoloader, which is used by Drupal and all modules; modules don't have to include the autoloader themselves.

I'm assuming you haven't used composer to set up the site initially, and have only downloaded the Drupal zip file and added your modules. Composer is unable to automatically determine dependencies from modules when using the zip file, but you can still add the dependencies yourself. From the root directory of your site (not the module with the dependency), add any required packages as a dependency to the project:

composer require ryanwinchester/hubspot-php

This will add the third-party package as a dependency of your site, install its files to the vendor directory, and also make it available to any modules.

Updating Drupal core with this setup is trickier however. You'll need to replace the composer.json file with the updated version to make sure that you get the correct dependencies for Drupal core, and then re-add any of your additional dependencies.

You can read the documentation on using Composer to manage an entire site: https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies

Using drupal-composer/drupal-project instead of the Drupal core zip file will allow you to add Drupal modules with composer, as well as automatically resolve and include any dependencies of those modules.

  • I actually did install everything including core with composer initially, things were just moved to an external host that handles core and does core updates for us after this was done. I used composer locally for the hubspot library and took the contents of the vendor folder in the core vendor folder and added the dependencies to the core composer.json folder but I still get the error Error: Class 'Drupal\SevenShores\Hubspot\Factory' not found. Was there a step I missed?
    – Matt
    Sep 12 '18 at 14:26
  • Also realized I used the wrong namespace but fixing that still didn't work and I get "Class 'SevenShores\Hubspot\Factory' not found"
    – Matt
    Sep 12 '18 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.