Created
October 7, 2017 20:10
-
-
Save mlutfy/3f7bd82adb35cfbf8f34e70078b85d3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d9540e65b7ef2faba3c32ff9a25d5fffca3a9995 Mon Sep 17 00:00:00 2001 | |
From: Mathieu Lutfy <mathieu@symbiotic.coop> | |
Date: Sat, 7 Oct 2017 16:07:52 -0400 | |
Subject: [PATCH] Add alterPriceSet hook. | |
--- | |
.../civicrm/CRM/Member/Form.php | 3 + | |
.../civicrm/CRM/Utils/Hook.php | 19 ++++++ | |
.../civicrm/Civi/Core/Event/AlterPriceSet.php | 69 ++++++++++++++++++++++ | |
3 files changed, 91 insertions(+) | |
create mode 100644 wp-content/civicrm/Civi/Core/Event/AlterPriceSet.php | |
diff --git a/wp-content/civicrm/CRM/Member/Form.php b/wp-content/civicrm/CRM/Member/Form.php | |
index 28043d2..8ed2d02 100644 | |
--- a/wp-content/civicrm/CRM/Member/Form.php | |
+++ b/wp-content/civicrm/CRM/Member/Form.php | |
@@ -425,6 +425,9 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { | |
$this->_priceSetId = self::getPriceSetID($formValues); | |
$priceSetDetails = self::getPriceSetDetails($formValues); | |
$this->_priceSet = $priceSetDetails[$this->_priceSetId]; | |
+ | |
+ CRM_Utils_Hook::alterPriceSet($this, $this->_priceSet); | |
+ | |
// process price set and get total amount and line items. | |
$this->ensurePriceParamsAreSet($formValues); | |
return $formValues; | |
diff --git a/wp-content/civicrm/CRM/Utils/Hook.php b/wp-content/civicrm/CRM/Utils/Hook.php | |
index 1484a1f..a75e511 100644 | |
--- a/wp-content/civicrm/CRM/Utils/Hook.php | |
+++ b/wp-content/civicrm/CRM/Utils/Hook.php | |
@@ -2294,6 +2294,25 @@ abstract class CRM_Utils_Hook { | |
} | |
/** | |
+ * This hook is called when loading a priceSet in a form. | |
+ * | |
+ * @param string $priceset | |
+ * The priceset that was loaded. | |
+ * @param string $form | |
+ * The form in which the priceset is loaded. | |
+ * | |
+ * @return null | |
+ * the return value is ignored | |
+ */ | |
+ public static function alterPriceSet(&$form, &$priceSet) { | |
+ $formName = get_class($form); | |
+ | |
+ $event = new \Civi\Core\Event\AlterPriceSet($formName, $form, $priceSet); | |
+ \Civi::dispatcher()->dispatch('hook_civicrm_alterPriceSet', $event); | |
+ return $event->getReturnValues(); | |
+ } | |
+ | |
+ /** | |
* This hook is called when the entries of the CSV Batch export are mapped. | |
* | |
* @param array $results | |
diff --git a/wp-content/civicrm/Civi/Core/Event/AlterPriceSet.php b/wp-content/civicrm/Civi/Core/Event/AlterPriceSet.php | |
new file mode 100644 | |
index 0000000..fc574c6 | |
--- /dev/null | |
+++ b/wp-content/civicrm/Civi/Core/Event/AlterPriceSet.php | |
@@ -0,0 +1,69 @@ | |
+<?php | |
+/* | |
+ +--------------------------------------------------------------------+ | |
+ | CiviCRM version 4.7 | | |
+ +--------------------------------------------------------------------+ | |
+ | Copyright CiviCRM LLC (c) 2004-2017 | | |
+ +--------------------------------------------------------------------+ | |
+ | This file is a part of CiviCRM. | | |
+ | | | |
+ | CiviCRM is free software; you can copy, modify, and distribute it | | |
+ | under the terms of the GNU Affero General Public License | | |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
+ | | | |
+ | CiviCRM is distributed in the hope that it will be useful, but | | |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
+ | See the GNU Affero General Public License for more details. | | |
+ | | | |
+ | You should have received a copy of the GNU Affero General Public | | |
+ | License and the CiviCRM Licensing Exception along | | |
+ | with this program; if not, contact CiviCRM LLC | | |
+ | at info[AT]civicrm[DOT]org. If you have questions about the | | |
+ | GNU Affero General Public License or the licensing of CiviCRM, | | |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
+ +--------------------------------------------------------------------+ | |
+ */ | |
+ | |
+namespace Civi\Core\Event; | |
+ | |
+/** | |
+ * Class AlterPriceSet | |
+ * @package Civi\API\Event | |
+ */ | |
+class AlterPriceSet extends GenericHookEvent { | |
+ | |
+ /** | |
+ * @var string | |
+ */ | |
+ public $formName; | |
+ | |
+ /** | |
+ * @var object | |
+ */ | |
+ public $form; | |
+ | |
+ /** | |
+ * @var object | |
+ */ | |
+ public $priceSet; | |
+ | |
+ /** | |
+ * @param $formName | |
+ * @param $form | |
+ * @param $priceSet | |
+ */ | |
+ public function __construct($formName, &$form, &$priceSet) { | |
+ $this->formName = $formName; | |
+ $this->form = &$form; | |
+ $this->priceSet = &$priceSet; | |
+ } | |
+ | |
+ /** | |
+ * @inheritDoc | |
+ */ | |
+ public function getHookValues() { | |
+ return array($this->formName, &$this->form, &$this->priceSet); | |
+ } | |
+ | |
+} | |
-- | |
2.11.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment