CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Drupal Modules "knowing" about CiviCRM
Pages: [1]

Author Topic: Drupal Modules "knowing" about CiviCRM  (Read 785 times)

e_mason

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 1
  • Eliot Mason
  • CiviCRM version: 4.05
  • CMS version: Drupal 7
  • MySQL version: 5.1xx
  • PHP version: 3.53
Drupal Modules "knowing" about CiviCRM
August 10, 2011, 08:41:28 am
I'm writing a Drupal (D7) module that uses the v3 API to create activities (basically, using Civi to record activity that happens on the Drupal side, using  hook_exit).  There's something I'm not getting about the configuration and how CiviCRM and Drupal play together....

None of the calls to the CiviCRM API work unless I "initialize" CiviCRM per this recent thread #20989 (For Joomla... but it works. sort of). This involves these lines (groan... not yet allowed to post code properly):using require_once with DRUPAL_ROOT to load civicrmsettings.settings.php (from the site directory), the config.php from the CRM core, api.php and the $config = CRM_Core_Config::singleton() statement.

BUT with those statements in place, CiviCRM is randomly throwing errors!  Specifically loading or refreshing /civicrm  randomly returns warnings, white screens, "Page Not Found", and even an "Oops! The path for including CiviCRM code files is not set properly...." And of course the page will also build perfectly with no errors about half the time. 

If I remove those initialization calls, all of CiviCRM works fine (except my module of course) so its not a larger problem with settings and paths.

So what's the proper way to tell a Drupal module about CiviCRM?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Drupal Modules "knowing" about CiviCRM
August 10, 2011, 08:49:02 am
Hi,

Not sure if it's white magic trick, but what I do is change the weight of the respective modules to get civicrm loaded before the modules that depend on it. It usually involves quasi random changes in the db and a lot of profanity.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Drupal Modules "knowing" about CiviCRM
August 10, 2011, 09:06:45 am

hey mason:

assuming you are not writing any civicrm related code in the hook_init function of your module,

civicrm_initialize( ); should work as is, since drupal loads all modules before invoking other hooks / menu system

get on irc and we can help debug

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

e_mason

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 1
  • Eliot Mason
  • CiviCRM version: 4.05
  • CMS version: Drupal 7
  • MySQL version: 5.1xx
  • PHP version: 3.53
Re: Drupal Modules "knowing" about CiviCRM
August 10, 2011, 09:21:48 am
That did the trick!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Drupal Modules "knowing" about CiviCRM

This forum was archived on 2017-11-26.