There has been some confusion about the $params vs $props variables, and some code was mistakenly using them interchangeably.
They are not the same, as CRM_Core_PseudoConstant::get expects sanitized input for $params, but CRM_*_DAO::buildOptions accepts raw user input as $props.
}
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);
* @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?
}
/**
- * 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.
\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);
}
}
* @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);
}
/**
$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++) {
}
$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);
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,
]);
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,
]);
$pcp2 = CRM_PCP_BAO_PCP::create($pcpParams);
// Get soft credit types, with the name column as the key.
- $soft_credit_types = CRM_Contribute_BAO_ContributionSoft::buildOptions("soft_credit_type_id", NULL, ["flip" => TRUE, 'labelColumn' => 'name']);
+ $soft_credit_types = CRM_Core_PseudoConstant::get('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', ['flip' => TRUE, 'labelColumn' => 'name']);
$pcp_soft_credit_type_id = $soft_credit_types['pcp'];
// Create two contributions assigned to this contribution page and