From de3440bdce610f1e63ee98db8c848ea419b29a69 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 20 Aug 2020 14:39:20 +0300 Subject: [PATCH] CATL-1613: Refactor CRM_Utils_Mail_CaseMail class - add a hook to change case email subject patterns --- CRM/Utils/Hook.php | 22 ++++++++++++++++++++++ CRM/Utils/Mail/CaseMail.php | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 381b69f8f685..85559c6429cc 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -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. diff --git a/CRM/Utils/Mail/CaseMail.php b/CRM/Utils/Mail/CaseMail.php index f8e33424e81a..97fc8ed98896 100644 --- a/CRM/Utils/Mail/CaseMail.php +++ b/CRM/Utils/Mail/CaseMail.php @@ -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;