Views Integration¶
Backdrop Views¶
Views is a powerful Backdrop module that allows you to display website content e.g. a list of latest news for the home page. CiviCRM integrates with Backdrop Views and allows CiviCRM data to be shown on your website. For instance, if you wanted to create a page called 'Partner Organizations' and display it publicly you could:
- Select criteria for what Contact data will be displayed such as:
- Organization contacts only
- That are tagged 'Partner' in CiviCRM
- That have a membership of status 'New' or 'Current'
- Choose which data will be shown such as:
- Organization name
- State/Province
- Website
- Phone number
- Choose to show the data in either table or paragraph format
- Allow the public to filter the results themselves by State/Province
This is just a simple example, the possibilities of Backdrop Views and CiviCRM are far reaching.
Configuration¶
These instructions assume CiviCRM and Backdrop are on separate databases located on the same physical host. If your CiviCRM and Backdrop are located within the same database the 12 steps below are not required.
- Before making any changes, it is strongly advised that you make backups of your mysql databases and settings.php file.
- If you have different database users for your CiviCRM and Backdrop databases, then you need to grant
SELECT
access for the Backdrop user to all the CiviCRM tables. - Make sure you are logged into your Backdrop site as the administrator.
- In the CiviCRM admin menu, visit Administer > System Settings > CMS Database Integration (
http://example.org/civicrm/admin/setting/uf?reset=1
) - You should see a page with output that begins with:
$databases['default']['default']['prefix']= array(
. It should look like the following snippet, qwhereexample_civicrm
is replaced with the name of the database that contains CiviCRM. (Note: that backticks are no longer included.)
$database_prefix = array(
'default' => '',
'civicrm_acl' => 'example_civicrm.',
'civicrm_acl_cache' => 'example_civicrm.',
//...
- Copy this setting output, including the trailing
);
-
Open the file
/settings.php
for editing from the root directory of the site, typicallypublic_html
on most servers.Note
This assumes you have a single site installation. The location of the settings file might be different depending on whether or not you have multiple sites
-
Go to the bottom of the file and paste in your previously-copied settings output here. If the settings.php file already includes an earlier version of the output please remove the earlier version before pasting the new output.
- Backdrop uses a simplified database string as follows:
$database = 'mysql://user:pass@localhost/database_name';
. To allow multiple databases, this will need to be converted to this format in thesettings.php
file as shown below. More on this.
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'database_name',
'username' => 'user',
'password' => 'pass',
'host' => 'localhost',
);
-
You may need to indicate the default prefix. If you see an error like the one below...
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'kckruppc_every.semaphore' doesn't exist: SELECT ...
...you need to include an additional line,
'default' => '<backdroptableprefix>'
, in yoursettings.php
just after$database_prefix = array(
. You can find more information on this error in this forum post. -
Save the file settings.php. You might want to clear your site cache at this point.
- You should now be able to create Backdrop Views based on CiviCRM data.
!!! note If you add a new set of custom fields to CiviCRM you will need to re-do these steps again. So any new fields in the field set can be accessed by Backdrop Views.
Note
If you are using Custom Data sets in CiviCRM, anytime you add a new data set (not just a field) you must repeat this process.
Creating Views Using CiviCRM Data¶
Views are located in the Structure section of the Backdrop administrative menu. When you create a View, give it a name and select what kind of data you wish to show.
Generally speaking if your view is focused on Contacts (which most are) you will select Show: CiviCRM Contacts. If you wish to display details about other CiviCRM data such as events, relationships, contributions or activities there are additional options that might provide more data fields for those types.
After the View is created, edit the fields, filters, display and other configurations to show the data exactly how you'd prefer. Views does take some experimentation and/or training to get it right. Feel free to ask questions on Stack Exchange or Mattermost — or hire a consultant if you become stuck.
Other Things Views and CiviCRM Can Do¶
- Lists of upcoming events
- Building reports on contributions, activities or event registrants
- Honor roll listing of recent donors
- Staff, board of directors or committee lists
- A list of current members
- ...and more!