Install
Works with Drupal: ^11.4 || ^12Using Composer to manage Drupal site dependencies
Alternative installation files
Release notes
This release keeps what hook_entity_presave implementations change when CiviCRM itself saves a record, and fixes a fatal error on current Drupal 12 development builds. There are no database updates or configuration
changes.
Overview
- Presave changes are kept on CiviCRM's own saves. Values set in
hook_entity_presave
during an API3, API4 or CiviCRM form save are now saved, both in CiviCRM and in Drupal fields. Modules that fill fields
in presave, such as AI Automators, now work on records created and updated in CiviCRM. - Drupal 12 fix. A Drupal core change committed November 4, 2026 stopped CiviCRM Entity's storage
class from loading on Drupal 12 development builds. Fixed. - CiviCRM 6.20. The base-field baseline now covers CiviCRM 6.20.0, which adds two Contribution Page
fields.
Merge request: !48
Presave changes on saves CiviCRM makes
CiviCRM Entity forwards CiviCRM's hook_civicrm_pre and hook_civicrm_post to Drupal's
entity hooks, so Drupal modules can react to records saved through API3, API4 and CiviCRM's forms. Until now, anything
a presave hook changed on those saves was lost:
- Creates: presave ran on an entity that was then discarded. Neither its Drupal field values nor its
changes to CiviCRM fields were saved. - Updates: presave saw the stored record without the values being written, and the original held the
same data, so modules saw no change. The update hooks also saw an original equal to the saved entity.
For example, an AI Automator on a CiviCRM activity called the AI provider on an API4 create and then lost the
result. On an API4 update it didn't run at all.
Now:
- On an update, presave sees the stored entity with the values being written applied, and its original is the stored
entity. - Changes presave makes to CiviCRM fields are written back into the same CiviCRM save. This covers core fields and
single-record custom fields, but not File custom fields or multi-record custom fields. - Drupal-only fields set in presave are saved once CiviCRM has written the record. The insert and update hooks then
receive that same entity, with the original from before the write. - The same applies to records CiviCRM creates inside a Drupal save, such as a new current employer created with an
individual. - CiviCRM dates in
YmdHisform (14 digits, as API3 and custom field params give them) are now read as
dates. They used to be taken as Unix timestamps.
Drupal's own saves, deletes and restores, and EntityTag and GroupContact writes, are unchanged.
Drupal 12
Drupal core's constructor property promotion task (#3278431) gave
several entity storage properties native types. CiviCRM Entity redeclared one of them without a type, and PHP refused
to load the class:
Type of Drupal\civicrm_entity\CiviEntityStorage::$entityFieldManager must be
Drupal\Core\Entity\EntityFieldManagerInterface
The module no longer redeclares properties it inherits from core only to document a narrower type:
CiviEntityStorage::$entityFieldManagerEntity\Query\CiviCRM\Condition::$queryEntity\Sql\CivicrmEntityStorageSchema::$storagePlugin\views\field\CustomEntityField::$fieldDefinition
If your code extends one of these classes and redeclares the same property, remove that redeclaration too. An
untyped redeclaration fails on Drupal 12 once core types the property, and a typed one fails on Drupal 11.
Saving Drupal fields also relied on the original magic property, which Drupal 12 removes. It now uses
getOriginal(). On Drupal 12, the old check always failed, so every update rewrote all of an entity's
Drupal field values. Unchanged values are now skipped, as on Drupal 11.
CiviCRM 6.20
CiviCRM 6.20 adds two Contribution Page fields, which appear as base fields of
civicrm_contribution_page:
thankyou_mode(list)thankyou_redirect_url(long text)
The test suite's base-field baseline now includes CiviCRM 6.20.0.
For developers
CiviEntityStorage::civiPreSave()takes an optional?array &$params, the params of
CiviCRM's write. Without it, the method behaves as before.CiviEntityStorage::holdCreatedId()takes optional params.- New:
CiviEntityStorage::claimCiviWrite()and the constant
CiviEntityStorage::WRITE_TOKEN. - Your own
hook_civicrm_preandhook_civicrm_postlisteners see a
civicrm_entity_write_tokenkey in the params of the writes CiviCRM Entity forwards. It pairs each pre hook
with its post hook. It doesn't appear in API3 or API4 results.
Known limitations
- CiviCRM's contact edit form fires its post hook without params. For contacts created through that form,
CiviCRM fields set in presave are saved, but Drupal-only fields are not, as before. Contact edits through the form
work. - Drupal fields are saved in the post hook. If an outer CiviCRM transaction later rolls back, their rows remain for a
record that no longer exists. - As before, presave runs before CiviCRM writes, so it also runs for a write that then fails. With AI Automators,
that means a provider call for a record that isn't saved.