0

Working on an extension that is aiming to be compatible with 4.6 and 4.7. The complete PCP api is only available as of 4.7 as far as I can tell.

So for 4.6 users, the extension can include the PCP api but "bypassed" for 4.7 users?

Because the api implementation in the extension is in api//. So how can 4.7 ignore this?

2 Answers 2

2

When you call an API, Civi does a search to locate it. That typically means searching the PHP include_path for a file named api/v3/{$entity}/{$action}.php or api/v3/{$entity}.php. The include_path is typically managed via hook_civicrm_config.

It sounds like want to change hook_civicrm_config so that the effect is:

  • Add /path/to/org.example.myext/ to the include_path unconditionally. This contains all you're normal/common files.
  • Add /path/to/org.example.myext/backports to the include_path if it's an old version (4.6). This contains only the backports/polyfills for older versions.

In most civix-based extensions, it does the first automatically with this snippet:

function {myext}_civicrm_config(&$config) {
  _{myext}_civix_civicrm_config($config);
}

The _{myext}_civix_civicrm_config() is a baseline/default implementation that unconditionally adds /path/to/org.example.myext/ to the include_path. Take a look at the code in _{myext}_civix_civicrm_config($config) to see how it works.

Then you can write a similar function to add /path/to/org.example.myext/backports. Finally, call it:

function {myext}_civicrm_config(&$config) {
  _{myext}_civix_civicrm_config($config)
  if (version_compare(CRM_Utils_System::version(), '4.7', '<')) {
    _{myext}_config_backports($config);
  }
}

function _{myext}_config_backports(&$config) {
  ...
}
0

You can use the civicrm setting API to check which version you are working with?

$version = civicrm_api3('Domain', 'getvalue', array('return' => "version"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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