From 214d5f517ae057de88bf81b01cdfe957057c5bec Mon Sep 17 00:00:00 2001 From: sushantpaste Date: Mon, 19 Aug 2019 17:25:21 +0530 Subject: [PATCH] dev/core#870 priceset hook --- CRM/Price/BAO/PriceField.php | 4 ++++ CRM/Price/BAO/PriceFieldValue.php | 4 ++++ CRM/Price/BAO/PriceSet.php | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 67bcd99b65..299832a3f6 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -61,6 +61,9 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { * @return CRM_Price_BAO_PriceField */ public static function add(&$params) { + $hook = empty($params['id']) ? 'create' : 'edit'; + CRM_Utils_Hook::pre($hook, 'PriceField', CRM_Utils_Array::value('id', $params), $params); + $priceFieldBAO = new CRM_Price_BAO_PriceField(); $priceFieldBAO->copyValues($params); @@ -70,6 +73,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { } $priceFieldBAO->save(); + CRM_Utils_Hook::post($hook, 'PriceField', $priceFieldBAO->id, $priceFieldBAO); return $priceFieldBAO; } diff --git a/CRM/Price/BAO/PriceFieldValue.php b/CRM/Price/BAO/PriceFieldValue.php index dd590ca82f..c01a61b7f1 100644 --- a/CRM/Price/BAO/PriceFieldValue.php +++ b/CRM/Price/BAO/PriceFieldValue.php @@ -48,6 +48,8 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { * @return CRM_Price_DAO_PriceFieldValue */ public static function add(&$params, $ids = []) { + $hook = empty($params['id']) ? 'create' : 'edit'; + CRM_Utils_Hook::pre($hook, 'PriceFieldValue', CRM_Utils_Array::value('id', $params), $params); $fieldValueBAO = new CRM_Price_BAO_PriceFieldValue(); $fieldValueBAO->copyValues($params); @@ -71,6 +73,8 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { } $fieldValueBAO->save(); + CRM_Utils_Hook::post($hook, 'PriceFieldValue', $fieldValueBAO->id, $fieldValueBAO); + // Reset the cached values in this function. CRM_Price_BAO_PriceField::getOptions(CRM_Utils_Array::value('price_field_id', $params), FALSE, TRUE); return $fieldValueBAO; diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index d178611508..7055bab12f 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -60,6 +60,9 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * @return CRM_Price_DAO_PriceSet */ public static function create(&$params) { + $hook = empty($params['id']) ? 'create' : 'edit'; + CRM_Utils_Hook::pre($hook, 'PriceSet', CRM_Utils_Array::value('id', $params), $params); + if (empty($params['id']) && empty($params['name'])) { $params['name'] = CRM_Utils_String::munge($params['title'], '_', 242); } @@ -81,7 +84,10 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { if (self::eventPriceSetDomainID()) { $priceSetBAO->domain_id = CRM_Core_Config::domainID(); } - return $priceSetBAO->save(); + $priceSetBAO->save(); + + CRM_Utils_Hook::post($hook, 'PriceSet', $priceSetBAO->id, $priceSetBAO); + return $priceSetBAO; } /** -- 2.25.1