3

We are building a Drupal distribution / installation profile similar to CiviCRM Starter Kit. This will install Drupal 7 and CiviCRM 4.3 while installing the distribution.

We want to add some CiviCRM Extensions like "Extended Reports for CiviCRM" etc. in our distribution so that whenever user will install the distribution, these CiviCRM Extensions also gets installed by default.

We have added these CiviCRM Extensions in drupal-org.make file like below,

libraries[nz.co.fuzion.extendedreport][download][type] = get
libraries[nz.co.fuzion.extendedreport][download][url] = "https://github.com/eileenmcnaughton/nz.co.fuzion.extendedreport/archive/master.zip"
libraries[nz.co.fuzion.extendedreport][destination] = "extensions"

and these get downloaded/unzipped when we run drupal packaging script (drush make). But we are not sure how to enable them as part of the distribution installation.

We know we can add the Drupal modules in profile.info file like below,

dependencies[] = civicrm

but don't know how and where to add CiviCRM Extensions so that they get installed as part of distribution / installation profile setup.

Please suggest how can we install CiviCRM Extensions automatically as part of installation profile setup.

10

The current API call requires more than just the key. To enable modules as part of an install profile, you simply need to include this code somewhere in the process when it's possible to initialize CiviCRM...

  if (!civicrm_initialize()) {
    drupal_set_message(t('Failed to initialize CiviCRM'));
    return;
  }

  require_once 'CRM/Extension/Manager.php';

  $params = array(
    'version' => 3,
    'sequential' => 1,
    'key' => 'org.civicrm.volunteer',
  );

  $result = civicrm_api('Extension', 'install', $params);

As long as the Extensions Directory and ResourceURL are set in the civicrm.settings.php, you should be set. I've been setting the Extensions Directory for Pantheon users, but still need to dynamically configure the ResourceURL https://drupal.org/node/1980088.

Rather than create a "Drupal distribution / installation profile similar to CiviCRM Starter Kit", PLEASE consider building on the CiviCRM Starter Kit by using it as the base distribution and contribute to maintaining it. Take a look at this patch and how the latest version of OpenAtrium builds on Panopoly.

https://drupal.org/comment/6117722#comment-6117722

http://drupalcode.org/project/openatrium.git/blob/refs/heads/7.x-2.x:/drupal-org-core.make

We really need more developers working to push the patches that are still requires back into CiviCRM to keep this stable. I hardly have time to figure out the changes with each CiviCRM release. It has taken several years to get to the point we can install and run CiviCRM from the /profiles directory, package CiviCRM w/ drush make, and rebuild the required libraries.

The CiviCRM Starter Kit was always designed to remain a base install to build other use case specific distributions on, but I've really been maintaining this on my own so far and would love some help.

UPDATE: I went ahead and created https://drupal.org/project/civicrm_extension_enabler since troubleshooting code in this queue is difficult. That module enables the CiviVolunteer extensions and works a site running https://dashboard.getpantheon.com/products/civicrm_starterkit/spinup once CiviVolunteer is uploaded to sites/all/extensions

I've started an issue to change the specific extensions hard coded in the .install to be an array of extensions populated by the distribution https://drupal.org/node/2159317

  • Thanks @kreynen. I have placed the following code in module's hook_install(). I am getting last successful message, which means civicrm is getting initialized. But civicrm extensions are not being installed. Looks like Extensions Directory and ResourceURL are not being set in the civicrm.settings.php although I am using drupal.org/files/1980088-create-extensions-dir-4.patch patch in drupal-org.make. – amitgoyal Dec 18 '13 at 11:28
  • function z_ext_install() { global $civicrm_setting; $d = realpath('.' . base_path()) . '/'; $civicrm_setting['Directory Preferences']['extensionsDir'] = $d . 'sites/all/extensions/'; if (!civicrm_initialize()) { drupal_set_message(t('Failed to initialize CiviCRM'));return;} $civicrm_path = drupal_get_path('module', 'civicrm') . '/'; require_once $civicrm_path . 'CRM/Extension/Manager.php'; $params = array('version' => 1.6, 'sequential' => 1,'key' => 'nz.co.fuzion.extendedreport'); $result = civicrm_api('Extension', 'install', $params); drupal_set_message('Ok.'); } – amitgoyal Dec 18 '13 at 11:31
  • 1
    In the params array, version isn't the version of the module... but the version of the API. I'd enable the Devel module and use dsm($result) to see the error civicrm_api is returning. – kreynen Dec 18 '13 at 17:02
  • I updated my answer with link to drupal.org/project/civicrm_extension_enabler. Just added steps to test to the project page. Let's move the discussion about making that module a flexible solution that any distribution can use to that project's issue queue since the original questions has been answered. – kreynen Dec 18 '13 at 17:52
1

I haven't done this exactly (using Drupal install-profiles), but there are two key ingredients that have helped me automate setup in other contexts:

  1. Traditionally (with Civi 3.x => 4.2 inclusive), one needed to create an extension directory and then set configuration options so that Civi would scan that directory. This is no longer necessary. Beginning in 4.3, you can put extension files anywhere in the CiviCRM source tree -- I'm partial to $civicrm_root/tools/extensions. Beginning in 4.4, you can also put extensions in $drupal_root/vendor.

  2. To activate the extension, you can call CiviCRM's Extension API. The call needs to come after CiviCRM's core platform has been installed and bootstrapped.

Some examples of using the API

## PHP
$result = civicrm_api('Extension', 'install', array('key' => 'my.extension.name'));

## PHP
$result = civicrm_api('Extension', 'install', array(
  'keys' => array(
    'my.extension.num1',
    'my.extension.num2',
    'my.extension.num3',
  ),
));

## CLI
drush cvapi extension.install key=my.extension.name

## CLI
drush cvapi extension.install keys=my.extension.num1,my.extension.num2,my.extension.num3

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.