CRM_Core_DAO::buildOptionsContext($context);
unset($apiRequest['params']['context'], $apiRequest['params']['field'], $apiRequest['params']['condition']);
- $baoName = _civicrm_api3_get_BAO($apiRequest['entity']);
- $options = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
+ // Legacy support for campaign_id fields which used to have a pseudoconstant
+ if ($fieldName === 'campaign_id') {
+ $campaignParams = [
+ 'select' => ['id', 'name', 'title'],
+ 'options' => ['limit' => 0],
+ ];
+ if ($context === 'match' || $context === 'create') {
+ $campaignParams['is_active'] = 1;
+ }
+ $labelField = $context === 'validate' ? 'name' : 'title';
+ $keyField = $context === 'match' ? 'name' : 'id';
+ $options = array_column(civicrm_api3('Campaign', 'get', $campaignParams)['values'], $labelField, $keyField);
+ }
+ else {
+ $baoName = _civicrm_api3_get_BAO($apiRequest['entity']);
+ $options = $baoName::buildOptions($fieldName, $context, $apiRequest['params']);
+ }
if ($options === FALSE) {
return civicrm_api3_create_error("The field '{$fieldName}' has no associated option list.");
}
$fieldValue = NULL;
}
}
- if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
+ if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id') {
$additional_lookup_params = [];
if (strtolower($entity) == 'address' && $fieldName == 'state_province_id') {
$country_id = _civicrm_api3_resolve_country_id($params);
/**
* Test civicrm_mailing_create.
*/
- public function testMailerCreateSuccess() {
- $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__);
+ public function testMailerCreateSuccess(): void {
+ $this->callAPISuccess('Campaign', 'create', ['name' => 'big campaign', 'title' => 'abc']);
+ $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now', 'campaign_id' => 'big campaign'], __FUNCTION__, __FILE__);
$jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals(1, $jobs['count']);
// return isn't working on this in getAndCheck so lets not check it for now