Skip to content

Commit

Permalink
CATL-1613: Refactor CRM_Utils_Mail_CaseMail class - add a hook to cha…
Browse files Browse the repository at this point in the history
…nge case email subject patterns
  • Loading branch information
i-grou committed Sep 10, 2020
1 parent aa58e9b commit e8f78a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,28 @@ public static function caseTypes(&$caseTypes) {
->invoke(['caseTypes'], $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
}

/**
* This hook is called when getting case email subject patterns.
*
* All emails related to cases have case hash/id in the subject, e.g:
* [case #ab12efg] 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) like:
* [(case|project|policy initiative) #hash]
* [(case|project|policy initiative) #id]
*
* @param array $subjectPatterns
* Cases related email subject regexp patterns.
*
* @return mixed
*/
public static function caseEmailSubjectPatterns(&$subjectPatterns) {
return self::singleton()
->invoke(['caseEmailSubjectPatterns'], $subjectPatterns, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseEmailSubjectPatterns');
}

/**
* This hook is called soon after the CRM_Core_Config object has ben initialized.
* You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
Expand Down
7 changes: 7 additions & 0 deletions CRM/Utils/Mail/CaseMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public function isCaseEmail ($subject) {
* @return array|string[]
*/
public function getSubjectPatterns() {
// Allow others to change patterns using hook.
if (empty($this->subjectPatternsHooked)) {
$patterns = $this->subjectPatterns;
CRM_Utils_Hook::caseEmailSubjectPatterns($patterns);
$this->subjectPatternsHooked = $patterns;
}

return !empty($this->subjectPatternsHooked)
? $this->subjectPatternsHooked
: $this->subjectPatterns;
Expand Down

0 comments on commit e8f78a0

Please sign in to comment.