Drupal8: Cannot use CiviCRM after installation. Must logout/login.
After performing the installation of Civi-D8, all potential Civi users need to logout/login - otherwise they will get weird error messages.
This issue was previously reported by Mark Hanna in JIRA as https://issues.civicrm.org/jira/browse/CRM-19878 and it seems to have gotten dropped in the JIRA/Gitlab transition.
- Setup a D8 site - include the CiviCRM code but do not activate it yet
- I used
d8prj-retype but hacked the
app/config/d8prj-re/install.shto skip CiviCRM installation
- I used
- Login to the web UI
- Activate the
- Navigate to
The screen displays an error:
Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing DB Constraint Violation - contact_id should possibly be marked as mandatory for DashboardContact,create API. If so, please raise a bug report.
This is because the currently logged-in user does not have a synchronized contact record (i.e. nothing in
The current work-around is to use out-of-band docs (ex: roundearth/drupal-civicrm-project README) and tell the admin to logout/login.
The record in
civicrm_uf_match should be auto-created.
In D7, it does so. It's implemented by way of
civicrm_invoke() which makes a call to
CRM_Core_BAO_UFMatch::synchronize(...). To wit: if you try to access any CiviCRM-based pages, then it will first check that your user account is synchronized.
The D8 module does do some user/contact synchronization, but only in a narrower range of cases (e.g. on-login). This is why the logout/login work-around helps.
Hypothetically, one could add a patch to the installer to trigger the sync for the current-user, but I think D7's approach is generally more robust. The former case would still be tempermental if (a) there are concurrent Drupal sessions for people who will have access to Civi or (b) you're loading DB snapshots (for dev/test or backup-restoration) in which the user/contact have not yet been sync'd.