Skip to content

Commit 5f754b5

Browse files
committed
CATL-1613: Refactor CRM_Utils_Mail_CaseMail class - add a hook to change case email subject patterns
1 parent 14364df commit 5f754b5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CRM/Utils/Hook.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,28 @@ public static function caseTypes(&$caseTypes) {
12711271
->invoke(['caseTypes'], $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
12721272
}
12731273

1274+
/**
1275+
* This hook is called when getting case email subject patterns.
1276+
*
1277+
* All emails related to cases have case hash/id in the subject, e.g:
1278+
* [case #ab12efg] Magic moment
1279+
* [case #1234] Magic is here
1280+
*
1281+
* Using this hook you can replace/enrich default list with some other
1282+
* patterns, e.g. include case type categories (see CiviCase extension) like:
1283+
* [(case|project|policy initiative) #hash]
1284+
* [(case|project|policy initiative) #id]
1285+
*
1286+
* @param array $subjectPatterns
1287+
* Cases related email subject regexp patterns.
1288+
*
1289+
* @return mixed
1290+
*/
1291+
public static function caseEmailSubjectPatterns(&$subjectPatterns) {
1292+
return self::singleton()
1293+
->invoke(['caseEmailSubjectPatterns'], $subjectPatterns, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseEmailSubjectPatterns');
1294+
}
1295+
12741296
/**
12751297
* This hook is called soon after the CRM_Core_Config object has ben initialized.
12761298
* You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.

CRM/Utils/Mail/CaseMail.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public function isCaseEmail ($subject) {
8585
* @return array|string[]
8686
*/
8787
public function getSubjectPatterns() {
88+
// Allow others to change patterns using hook.
89+
if (empty($this->subjectPatternsHooked)) {
90+
$patterns = $this->subjectPatterns;
91+
CRM_Utils_Hook::caseEmailSubjectPatterns($patterns);
92+
$this->subjectPatternsHooked = $patterns;
93+
}
94+
8895
return !empty($this->subjectPatternsHooked)
8996
? $this->subjectPatternsHooked
9097
: $this->subjectPatterns;

0 commit comments

Comments
 (0)