From d235a2ba2735b68cdce105da960e6af2e2546128 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 17 Oct 2022 20:57:21 -0400 Subject: [PATCH] PriceSet - Fix metadata for extends column, for SearchKit compatibility --- CRM/Price/BAO/PriceSet.php | 23 +++++++++++++++++++ CRM/Price/DAO/PriceSet.php | 7 +++--- tests/phpunit/CRM/Core/PseudoConstantTest.php | 2 +- xml/schema/Price/PriceSet.xml | 5 ++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index ec714e2aeb..15570a7787 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1705,4 +1705,27 @@ WHERE ct.id = cp.financial_type_id AND $form->assign('ispricelifetime', $checklifetime); } + /** + * Pseudoconstant options for the `extends` field + * + * @return array + */ + public static function getExtendsOptions(): array { + $enabledComponents = CRM_Core_Component::getEnabledComponents(); + $allowedComponents = [ + 'CiviEvent' => ts('Event'), + 'CiviContribute' => ts('Contribution'), + 'CiviMember' => ts('Membership'), + ]; + $result = []; + foreach (array_intersect_key($enabledComponents, $allowedComponents) as $component) { + $result[] = [ + 'id' => $component->componentID, + 'name' => $component->name, + 'label' => $allowedComponents[$component->name], + ]; + } + return $result; + } + } diff --git a/CRM/Price/DAO/PriceSet.php b/CRM/Price/DAO/PriceSet.php index 609218b750..9afc97784f 100644 --- a/CRM/Price/DAO/PriceSet.php +++ b/CRM/Price/DAO/PriceSet.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Price/PriceSet.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:23b87e351bab2f2cefd04fd6ea4a6ee5) + * (GenCodeChecksum:01bf707155bf45d044239f9001cfe42d) */ /** @@ -410,13 +410,12 @@ class CRM_Price_DAO_PriceSet extends CRM_Core_DAO { 'entity' => 'PriceSet', 'bao' => 'CRM_Price_BAO_PriceSet', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, 'html' => [ 'type' => 'Text', ], 'pseudoconstant' => [ - 'table' => 'civicrm_component', - 'keyColumn' => 'id', - 'labelColumn' => 'name', + 'callback' => 'CRM_Price_BAO_PriceSet::getExtendsOptions', ], 'add' => '3.1', ], diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index f2e0f52607..a69160f0a3 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -310,7 +310,7 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { ], [ 'fieldName' => 'extends', - 'sample' => 'CiviEvent', + 'sample' => 'Event', ], [ 'fieldName' => 'financial_type_id', diff --git a/xml/schema/Price/PriceSet.xml b/xml/schema/Price/PriceSet.xml index c52132cd7a..3687426043 100644 --- a/xml/schema/Price/PriceSet.xml +++ b/xml/schema/Price/PriceSet.xml @@ -134,10 +134,9 @@ true What components are using this price set? - civicrm_component
- id - name + CRM_Price_BAO_PriceSet::getExtendsOptions
+ SEPARATOR_BOOKEND 3.1 Text -- 2.25.1