Commit 2e67fc23 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

implement deleting of message template when corresponding mosaico template is deleted #18

parent 02fc0f90
<?php
require_once 'mosaicomsgtpl.civix.php';
use CRM_Mosaicomsgtpl_ExtensionUtil as E;
use CRM_Mosaicomsgtpl_ExtensionUtil as E;
/**
* Implements hook_civicrm_post()
*
* This function is used to keep mosaico template and message template in sync
*/
function mosaicomsgtpl_civicrm_post($op, $objectName, $objectId, &$objectRef = NULL) {
if (($op === 'create' || $op === 'edit') && $objectName === 'MosaicoTemplate') {
if (Civi::settings()->get('mosaicomsgtpl_suspend')) {
......@@ -16,6 +21,31 @@ function mosaicomsgtpl_civicrm_post($op, $objectName, $objectId, &$objectRef = N
}
}
/**
* Implements hook_civicrm_pre()
*
* This function is used to delete message template when a corresponding mosico template in deleted
*/
function mosaicomsgtpl_civicrm_pre($op, $objectName, $objectId, &$objectRef = NULL) {
if ($objectName === 'MosaicoTemplate' && $op === 'delete') {
if (Civi::settings()->get('mosaicomsgtpl_suspend')) {
return;
}
// get the message_template_id
$result = civicrm_api3('MosaicoTemplate', 'get', [
'sequential' => 1,
'return' => ["msg_tpl_id"],
'id' => $objectId,
]);
// delete message template
civicrm_api3('MessageTemplate', 'delete', [
'id' => $result['values'][0]['msg_tpl_id'],
]);
}
}
/**
* Implements hook_civicrm_config().
*
......@@ -163,7 +193,6 @@ function mosaicomsgtpl_civicrm_alterMailContent(&$content) {
$content['html'] = strtr($content['html'], $replacements);
$content['text'] = strtr($content['text'], $replacements);
}
}
// --- Functions below this ship commented out. Uncomment as required. ---
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment