Discount - Dynamic pseudoconstant for price_set_id field
authorcolemanw <coleman@civicrm.org>
Tue, 22 Aug 2023 21:54:07 +0000 (17:54 -0400)
committercolemanw <coleman@civicrm.org>
Tue, 22 Aug 2023 21:54:07 +0000 (17:54 -0400)
CRM/Core/BAO/Discount.php
CRM/Core/DAO/Discount.php
xml/schema/Core/Discount.xml

index 2b63fd5c363519dd86d60f8cc561622fce525e9f..fb2b71bf0042b686d71b6b5324d6a17b7047efa3 100644 (file)
@@ -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.
    *
index 1d9810753e9a6de99cfa4141037f35370f38462f..f37e4d7cda24373992ec9f37011da1ed7becddc8 100644 (file)
@@ -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',
index c1113add761a36df4b3451ffbeb207120574b036..e9cc6d423d47466e048239bf0280dc71c52892c8 100644 (file)
@@ -65,6 +65,7 @@
     <html>
       <label>Price Set</label>
       <type>Select</type>
+      <controlField>entity_id</controlField>
     </html>
     <add>4.3</add>
   </field>