Answers.Body: <p>When you call an API, Civi does a search to locate it. That typically means searching the PHP <code>include_path</code> for a file named <code>api/v3/{$entity}/{$action}.php</code> or <code>api/v3/{$entity}.php</code>. The <code>include_path</code> is typically managed via <code>hook_civicrm_config</code>.</p>
  
  <p>It sounds like want to change <code>hook_civicrm_config</code> so that the effect is:</p>
  
  <ul>
  <li>Add <code>/path/to/org.example.myext/</code> to the <code>include_path</code> unconditionally. This contains all you're normal/common files.</li>
  <li>Add <code>/path/to/org.example.myext/backports</code> to the <code>include_path</code> if it's an old version (4.6). This contains only the backports/polyfills for older versions.</li>
  </ul>
  
  <p>In most <code>civix</code>-based extensions, it does the first automatically with this snippet:</p>
  
  <pre><code>function {myext}_civicrm_config(&amp;$config) {
    _{myext}_civix_civicrm_config($config);
  }
  </code></pre>
  
  <p>The <code>_{myext}_civix_civicrm_config()</code> is a baseline/default implementation that unconditionally adds <code>/path/to/org.example.myext/</code> to the <code>include_path</code>. Take a look at the code in <code>_{myext}_civix_civicrm_config($config)</code> to see how it works.</p>
  
  <p>Then you can write a similar function to add <code>/path/to/org.example.myext/backports</code>. Finally, call it:</p>
  
  <pre><code>function {myext}_civicrm_config(&amp;$config) {
    _{myext}_civix_civicrm_config($config)
    if (version_compare(CRM_Utils_System::version(), '4.7', '&lt;')) {
      _{myext}_config_backports($config);
    }
  }
  
  function _{myext}_config_backports(&amp;$config) {
    ...
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-20T18:16:57.530Z
Answers.LastActivityDate: 2017-03-20T18:16:57.530Z
Answers.UserDisplayName: Tim Otten
Answers.Body: <p>You can use the civicrm setting API to check which version you are working with? </p>
  
  <pre><code>$version = civicrm_api3('Domain', 'getvalue', array('return' =&gt; "version"));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-20T14:55:58.480Z
Answers.LastActivityDate: 2017-03-20T14:55:58.480Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>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.</p>
  
  <p>So for 4.6 users, the extension can include the PCP api but "bypassed" for 4.7 users?</p>
  
  <p>Because the api implementation in the extension is in api/<em>/</em>. So how can 4.7 ignore this?</p>
  
Tags: <extension>
Title: Is there a civi way to manage API compatibility across CiviCRM versions?
ThreadText: # Is there a civi way to manage API compatibility across CiviCRM versions?
  
  (Asked by: username_0 on 2017-03-20)
  
  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?
  
  **Tags:** extension
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-03-20. Score: 2 | Accepted answer
  
  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) {
    ...
  }
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2017-03-20. Score: 0
  
  You can use the civicrm setting API to check which version you are working with?
  
  ```
  $version = civicrm_api3('Domain', 'getvalue', array('return' => "version"));
  
  ```
  
  
  ---
  
  