6

When setting up a Drupal 8 with separate CiviCRM database, the Drupal views cannot read the CiviCRM database:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.civicrm_contact' doesn't exist: SELECT civicrm_contact.id AS id, civicrm_contact.organization_name AS civicrm_contact_organization_name FROM {civicrm_contact} civicrm_contact LIMIT 11 OFFSET 0; Array ( )

Checking the civicrm_views module I suppose there are some changes needed in the civicrm_views_views_data() function to connect to the right database for the CiviCRM data.

I also tried to create a view based on entities from the CiviCRM Entity module, but have the same error there.

Anybody got this working or has some hints how to do it?

6
  • 1
    Hi Hans, I know Jaap Jansma uses this extension: lab.civicrm.org/extensions/dataprocessor to deal with Views from an external CiviCRM. I will point out your question to him. Commented Dec 19, 2018 at 10:54
  • 1
    You can indeed use the data processor extension for that. You also need the CiviMRF core module from github.com/CiviMRF/cmrf_core (which also contains the cmrf_views module). The CiviMRF is capable of connecting to an external civicrm and with cmrf_views you can setup views to retrieve data from the CiviCRM API. With the data processor you can create your own custom API's (or views). The data processor is at the moment work in progress and not well tested but that might change in the coming months. Commented Dec 19, 2018 at 14:04
  • jaap can you add this as an Answer
    – petednz - fuzion
    Commented Dec 19, 2018 at 19:05
  • Is this specific to drupal 8? Did you try the "prefix" in settings.php the same as in drupal 7 as described here? docs.civicrm.org/sysadmin/en/latest/integration/drupal/views
    – Demerit
    Commented Dec 20, 2018 at 1:25
  • @Demerit: it is indeed for Drupal 8 I'm searching, the same setup works perfectly in Drupal 7: 2 databases: 1 for Drupal and 1 for CiviCRM (to have extra security for the contact data). The prefix method is if you want both Drupal and CiviCRM in a single database. Commented Mar 20, 2019 at 19:42

2 Answers 2

9

I had the same problem today, so I looked in the source code.

In civicrm.install there's a function called _civicrm_get_db_config. It's looking in the $databases array for an element with a key civicrm. So I added this to settings.php:

$databases['civicrm']['default'] = array (
  'database' => 'civi_db_name',
  'username' => 'mysqluser',
  'password' => 'redacted',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

I then had to clear all caches before it worked, but work it does.

3
1

You can use the data processor extension (https://lab.civicrm.org/extensions/dataprocessor) for that. The data processor is an extension for CiviCRM which gets data from CiviCRM and exposes this to the API (it is possible to add your own outputs, e.g, csv file, page etc..)

At the Drupal side you need the CiviMRF Core Module (https://github.com/CiviMRF/cmrf_core). The CiviMRF is capable of connecting to an external civicrm and with cmrf_views you can setup views to retrieve data from the CiviCRM API.

With the data processor you can create your own custom API's (or views).

All this is still work in progress but functional working. I hope to write a blog post on how the data processor works with Drupal views in the near future.

This will also work when CiviCRM is installed in the same Drupal environment. The CMRF core module provides a 'local' connection.

4
  • I believe the question being asked here isn't "How to access a separate CMS instance with CiviCRM" but "I have a single instance with my CMS MySQL tables and CRM MySQL tables in separate databases." Commented Dec 20, 2018 at 14:52
  • You are right and the answer is that above also works with CiviCRM installed in the same CMS. Commented Dec 21, 2018 at 9:00
  • 1
    It looks like a good way to do it but unfortunately in the Drupal 8 version of the CiviMRF Core Module there is no cmrf_views (yet). Commented Mar 20, 2019 at 19:40
  • Yes the civimrf module is not yet well suported by drupal 8. It would cost quite a bit to make it drupal 8 compatible (as drupal 8 is quite different from drupal 7). So it is almost a redevelopment of the module. My assumption earlier was that this module was easily compatible with drupal 8. Commented Mar 21, 2019 at 8:45

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