hook_civicrm_caseEmailSubjectPatterns¶
Summary¶
This hook is called when getting case email subject patterns.
Notes¶
All emails related to cases have case hash/id in the subject, e.g:
[case #ab12efb] Magic moment
[case #1234] Magic is here
Using this hook you can replace/enrich default list with some other patterns, e.g. include case type categories (see CiviCase extension).
This hook is called in CRM_Utils_Mail_CaseMail
class, which is meant to be the
single source of truth for case email subject patterns. You should always use
CRM_Utils_Mail_CaseMail->getSubjectPatterns()
or
CRM_Utils_Mail_CaseMail->isCaseEmail()
to handle email subject processing.
Definition¶
hook_civicrm_caseEmailSubjectPatterns(&$subjectPatterns)
Parameters¶
- array $subjectPatterns - the list of case email subject regex patterns.
Example¶
function civitest_civicrm_caseEmailSubjectPatterns(&$subjectPatterns) {
// Case email subject have 'case' label at the beginning, so we could
// just use it for further processing, but if you want to avoid using
// hardcoded values, you can do this:
$mailUtils = new CRM_Utils_Mail_CaseMail();
$caseLabel = $mailUtils->get('caseLabel');
// Add case type category names to patterns, so civicrm would
// treat them as case emails too. After this loop $subjectPatterns would
// look like this: array(
// '/\[(case|project|policy initiative) #([0-9a-f]{7})\]/i',
// '/\[(case|project|policy initiative) #(\d+)\]/i',
// ).
// (Hardcoded category names are used in this example for the sake of
// simplicity, but I guess you know how to handle it in your code)
foreach ($subjectPatterns as &$pattern) {
$pattern = str_replace($caseLabel, '(' . $caseLabel . '|project|policy initiative)', $pattern);
}
}