I installed the Drupal 8 version of this module (alpha2) and added the "mailchimp/mailchimp": ">=2.0.4" line to composer.json in my Drupal root, then ran composer update.

I then enabled MailChimp on my server, which forced me to install Composer Manager as a dependency. But, without configuring Composer Manager, I was able to pull in my lists from MailChimp and subscribe/unsubscribe users normally because I had already added the library via composer on the command line.

Does this module really need Composer Manager as a dependency? I'm just getting started with Drupal 8, so if I'm doing something wrong/dangerous here, please let me know.

Comments

ptmkenny created an issue. See original summary.

Greg Boggs’s picture

Composer manager is a tool to help install libraries. If you've got the MailChimp library installed and working then you're all set. We may be reassessing composer manager in the near future as composer usage in Drupal matures.

Perignon’s picture

There is a reason for Composer Manager in D8.

The reason is this; there is no way (yet) of managing dependencies for contributed modules. Composer is designed to work over an entire project for dependencies. A single composer.json for the project, the Drupal installation in this case. Composer doesn't know about module in a Drupal installation and does not know there are composer.json's in every module folder - Composer Manager however does. Modules cannot alter (hack) core files on installation and therefore cannot touch the composer.json that sits at the root of Drupal to inject dependencies. What you did my manually editing the composer.json at the root of Drupal works of course, but that is not something a module can do on installation - see Do Not Hack Core.

Composer Manager fills the gap to allow module dependencies to be resolved independent of Drupal core.

As @Gregg Boggs said, composer usage still has some growing to do with Drupal, and this module dependency is one of the big rocks to crack.

ptmkenny’s picture

Thanks for the response. It's certainly true that Drupal 8 modules are at present definitely taking a variety of approaches to dependencies; the CloudFlare module (another contrib module to interface with a third-party API), for example, recommends modifying composer.json directly.

I know about not hacking core, but it seems to me that composer.json is like the .htaccess file-- if you need to change it, you can't use a hook or something to override it; you have to modify the original. In any case, though, this is a question for the larger community, and I now understand your approach for Mailchimp at this time. Many thanks!

Perignon’s picture

A workaround could also be supplying patch files that must be applied. This is done with certain modules for .htaccess changes, since again they do not want a module touching a core file, even .htaccess.

I should go look to see if there is an issue for core yet about this.

MegaChriz’s picture

I read on the page "Composer Manager for Drupal 8" that it is not recommended to let modules depend on Composer Manager:

Note: Your module should not depend on Composer Manager. The module itself is not required to be enabled for commands to work, and other users might use different Composer strategies that don't involve Composer Manager.

But I can understand that if the module didn't depend on Composer Manager, it would be a major struggle for users that do not know what Composer is to install MailChimp on D8.

Perignon’s picture

Correct, and composer manager also gives you central management of the libraries it downloads (sites/all/libraries/composer). I am not the maintainer of the Mailchimp module (I am looking at using it), but maintain some other modules one of which requires composer manager to operate.

Greg Boggs’s picture

While I agree in spirit, there's a thread full of people who fail at composer manager even when we mark it as a dependency because it requires additional set up. Feel free to lend folks a hand giving advice in how to get MailChimp installed here: https://www.drupal.org/node/2612452. While the CloudFlare module may recommend hacking core directly, it's unlikely that we will go that route.

Tsjippy’s picture

My hosting service does not allow Drush...
Does this mean I cannot use Mailchimp or even drupal 8 anymore?

Perignon’s picture

Time to find a new hosting company. I cannot imagine not having Drush to run my sites.

Greg Boggs’s picture

You do not need a web hosting company that supports Drush to run Composer Manager. Instead, you can run composer manager on your own computer and then FTP the results to your hosting company with FileZilla. I would not recommend using a hosting that only allows FTP access in 2016, but there are a lot of people who do.

dinarcon’s picture

Hello,

According to https://www.drupal.org/node/2404131:

Drupal's root composer.json file has been made user editable so that individual projects can specify their own dependencies independent of Drupal core. This allows users to manage Drupal core, modules, themes, PHP Dependencies, etc. from composer.json.

If we also take into consideration that Composer Manager itself recommends against making it a dependency, as noted by @MegaChriz in #6, I think it should be removed as a Mailchimp dependency. Instead, we could check if the class has been loaded and show an error message and/or implement hook_requirements to let the user know that something else is needed for Mailchimp to work.

In my case, I was using the Drupal Composer project (https://github.com/drupal-composer/drupal-project) which made the use of Composer Manager redundant. Other autoloading methods might also been implemented. Instead of enforcing one, we can let the user pick the one he or she prefers.

I can work on a patch if we agree on a approach to follow.

Thanks for your work on the module.

Greg Boggs’s picture

Patches are welcome. While I can't say with any certainty what the future looks like for library handling in Drupal 8, you're more than welcome to write and post a patch.

platinum1’s picture

@dinarcon Did you write a patch for this?

ruscoe’s picture

We just released 8.x-1.0, which does not depend on Composer Manager:

https://www.drupal.org/node/2706695

This release uses a new library for version 3.0 of MailChimp's API and we decided bundling the library with the module was the best option for now.

ruscoe’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dremy’s picture

Now that Drupal and Composer are more friendly, should this be rehashed?

svendecabooter’s picture

I created a new followup issue for that, since this one is marked as closed: #2845950: Install Mailchimp PHP API via Composer