diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index 3f8653147486..6b523272a351 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -545,7 +545,7 @@ public static function group( } if ($allGroups == NULL) { - $allGroups = CRM_Contact_BAO_Contact::buildOptions('group_id', NULL, ['onlyActive' => FALSE]); + $allGroups = CRM_Contact_BAO_Contact::buildOptions('group_id', 'get'); } $acls = CRM_ACL_BAO_Cache::build($contactID); diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 4f507b1e6ad7..3914a1c3667d 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -779,8 +779,7 @@ public static function bulkAddContactsToGroup( * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = []) { - - $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $props, $context); + $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, [], $context); // Sort group list by hierarchy // TODO: This will only work when api.entity is "group_contact". What about others? diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 1bf45bdcdcb1..804af1d112ba 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -955,31 +955,20 @@ public static function getInactiveStatuses() { } /** - * Get options for the called BAO object's field. - * - * This function can be overridden by each BAO to add more logic related to context. - * The overriding function will generally call the lower-level CRM_Core_PseudoConstant::get - * - * @param string $fieldName - * @param string $context - * @see CRM_Core_DAO::buildOptionsContext - * @param array $props - * whatever is known about this bao object. - * - * @return array|bool + * @inheritDoc */ public static function buildOptions($fieldName, $context = NULL, $props = []) { - + $params = []; switch ($fieldName) { case 'payment_processor_id': if (isset(\Civi::$statics[__CLASS__]['buildoptions_payment_processor_id'])) { return \Civi::$statics[__CLASS__]['buildoptions_payment_processor_id']; } $baoName = 'CRM_Contribute_BAO_ContributionRecur'; - $props['condition']['test'] = "is_test = 0"; - $liveProcessors = CRM_Core_PseudoConstant::get($baoName, $fieldName, $props, $context); - $props['condition']['test'] = "is_test != 0"; - $testProcessors = CRM_Core_PseudoConstant::get($baoName, $fieldName, $props, $context); + $params['condition']['test'] = "is_test = 0"; + $liveProcessors = CRM_Core_PseudoConstant::get($baoName, $fieldName, $params, $context); + $params['condition']['test'] = "is_test != 0"; + $testProcessors = CRM_Core_PseudoConstant::get($baoName, $fieldName, $params, $context); foreach ($testProcessors as $key => $value) { if ($context === 'validate') { // @fixme: Ideally the names would be different in the civicrm_payment_processor table but they are not. @@ -995,7 +984,7 @@ public static function buildOptions($fieldName, $context = NULL, $props = []) { \Civi::$statics[__CLASS__]['buildoptions_payment_processor_id'] = $allProcessors; return $allProcessors; } - return parent::buildOptions($fieldName, $context, $props); + return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); } } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index d5d4a72048b5..e9e5732509f2 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2570,14 +2570,16 @@ public static function appendPseudoConstantsToFields(&$fields) { * @param string $context * @see CRM_Core_DAO::buildOptionsContext * @param array $props - * whatever is known about this bao object. + * Raw field values; whatever is known about this bao object. + * + * Note: $props can contain unsanitized input and should not be passed directly to CRM_Core_PseudoConstant::get * * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = []) { // If a given bao does not override this function $baoName = get_called_class(); - return CRM_Core_PseudoConstant::get($baoName, $fieldName, $props, $context); + return CRM_Core_PseudoConstant::get($baoName, $fieldName, [], $context); } /** diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index c8e0f2a7b7da..0b7cbf2f648e 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -419,7 +419,7 @@ public static function formRule($fields, $files, $form) { $publicOptionCount = $_flagOption = $_rowError = 0; $_showHide = new CRM_Core_ShowHideBlocks('', ''); - $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, ['labelColumn' => 'name']); + $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', 'validate'); for ($index = 1; $index <= self::NUM_OPTION; $index++) { diff --git a/CRM/Price/Form/Option.php b/CRM/Price/Form/Option.php index 56c9aadcc736..1b8308d1eb1e 100644 --- a/CRM/Price/Form/Option.php +++ b/CRM/Price/Form/Option.php @@ -286,7 +286,7 @@ public static function formRule($fields, $files, $form) { } $priceField = CRM_Price_BAO_PriceField::findById($fields['fieldId']); - $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, ['labelColumn' => 'name']); + $visibilityOptions = CRM_Core_PseudoConstant::get('CRM_Price_BAO_PriceFieldValue','visibility_id', ['labelColumn' => 'name']); $publicCount = 0; $options = CRM_Price_BAO_PriceField::getOptions($priceField->id); diff --git a/tests/phpunit/CRM/Price/Form/FieldTest.php b/tests/phpunit/CRM/Price/Form/FieldTest.php index 379265097600..f7ba89f11d17 100644 --- a/tests/phpunit/CRM/Price/Form/FieldTest.php +++ b/tests/phpunit/CRM/Price/Form/FieldTest.php @@ -11,7 +11,7 @@ class CRM_Price_Form_FieldTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ + $this->visibilityOptionsKeys = CRM_Core_PseudoConstant::get('CRM_Price_BAO_PriceFieldValue', 'visibility_id', [ 'labelColumn' => 'name', 'flip' => TRUE, ]); diff --git a/tests/phpunit/CRM/Price/Form/OptionTest.php b/tests/phpunit/CRM/Price/Form/OptionTest.php index 64fbd4ffc6ef..f9ac7ed7b7f5 100644 --- a/tests/phpunit/CRM/Price/Form/OptionTest.php +++ b/tests/phpunit/CRM/Price/Form/OptionTest.php @@ -15,10 +15,10 @@ class CRM_Price_Form_OptionTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); - $this->visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ + $this->visibilityOptions = CRM_Core_PseudoConstant::get('CRM_Price_BAO_PriceFieldValue', 'visibility_id', [ 'labelColumn' => 'name', ]); - $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ + $this->visibilityOptionsKeys = CRM_Core_PseudoConstant::get('CRM_Price_BAO_PriceFieldValue', 'visibility_id', [ 'labelColumn' => 'name', 'flip' => TRUE, ]);