From: colemanw Date: Tue, 22 Aug 2023 21:54:07 +0000 (-0400) Subject: Discount - Dynamic pseudoconstant for price_set_id field X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=042a66302bed61e95c7a45ab102d8d289c494083;p=civicrm-core.git Discount - Dynamic pseudoconstant for price_set_id field --- diff --git a/CRM/Core/BAO/Discount.php b/CRM/Core/BAO/Discount.php index 2b63fd5c36..fb2b71bf00 100644 --- a/CRM/Core/BAO/Discount.php +++ b/CRM/Core/BAO/Discount.php @@ -83,6 +83,16 @@ class CRM_Core_BAO_Discount extends CRM_Core_DAO_Discount { return $optionGroupIDs; } + public static function buildOptions($fieldName, $context = NULL, $values = []) { + // Special logic for fields whose options depend on context or properties + if ($fieldName === 'price_set_id' && !empty($values['entity_table']) && !empty($values['entity_id'])) { + $priceSetIds = self::getOptionGroup($values['entity_id'], $values['entity_table']); + $params = ['condition' => ['id IN (' . implode(',', $priceSetIds) . ')']]; + return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); + } + return parent::buildOptions($fieldName, $context, $values); + } + /** * Determine in which discount set the registration date falls. * diff --git a/CRM/Core/DAO/Discount.php b/CRM/Core/DAO/Discount.php index 1d9810753e..f37e4d7cda 100644 --- a/CRM/Core/DAO/Discount.php +++ b/CRM/Core/DAO/Discount.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Discount.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:63b35b634e2bbd8e56e55e87c7d06f91) + * (GenCodeChecksum:8d80d6c79c0ecd92e22ed5ac74d59700) */ /** @@ -210,6 +210,7 @@ class CRM_Core_DAO_Discount extends CRM_Core_DAO { 'html' => [ 'type' => 'Select', 'label' => ts("Price Set"), + 'controlField' => 'entity_id', ], 'pseudoconstant' => [ 'table' => 'civicrm_price_set', diff --git a/xml/schema/Core/Discount.xml b/xml/schema/Core/Discount.xml index c1113add76..e9cc6d423d 100644 --- a/xml/schema/Core/Discount.xml +++ b/xml/schema/Core/Discount.xml @@ -65,6 +65,7 @@ Select + entity_id 4.3