hook_civicrm_notePrivacy¶
Summary¶
This hook was removed in v6.9 in favor of hook_civicrm_selectWhereClause.
Availability¶
- Added in 3.3+ to affect smarty-based pages and forms (not called by APIv3 or APIv4).
- In 5.67 it was called updated to be called by APIv4/SearchKit, and also deprecated. This provided a transition period to allow migration.
- It was removed in 6.9.
Migration¶
This hook was removed because it is not efficient to call a hook for every row after running a query, and also because this hook only affects one type of entity (Notes).
By contrast, hook_civicrm_selectWhereClause is called once, before running a query, and can be used for all entity types.
Existing hook implementations will need to be refactored from a post-query to a pre-query paradigm.
Before¶
/**
* Implements hook_civicrm_notePrivacy
* This is called once per note after a note is fetched from the DB
* It adds the magic `notePrivacy_hidden` value which overrides privacy settings.
*/
function example_civicrm_notePrivacy(&$noteRecord) {
// Our site added a new option '2' to the note_privacy option group,
// which we enforce here so only users with x permission can see the note.
if ($noteValues['privacy'] == 2) {
$noteValues['notePrivacy_hidden'] = CRM_Core_Permission::check('x');
}
}
/**
* Implements hook_civicrm_selectWhereClause
*/
function example_civicrm_selectWhereClause($entityName, &$clauses, $userId) {
// Amend note privacy clause (only relevant if user lacks 'view all notes' permission)
if ($entityName === 'Note' && !CRM_Core_Permission::check('view all notes', $userId)) {
if (CRM_Core_Permission::check('view note type two', $userId)) {
// What's going on here is that `$clauses['privacy']` already contains an array of arrays
// (which means OR).
// @see CRM_Core_BAO_Note::addSelectWhereClause()
// The existing values are `"= 0" OR "= 1 AND {contact_id} = $currentUser"`
// So here we are adding a 3rd condition IF the above permission check passes, to allow
// our privileged users to see our special privacy type 2.
$clauses['privacy'][0][] = '= 2';
}
}
}
Definition¶
hook_civicrm_notePrivacy(&$noteValues)
Parameters¶
- array
$noteValues- The values from an object of typeCRM_Core_DAO_Note, converted to an array.
Returns¶
void