CRM_Campaign_BAO_Campaign::accessCampaign()
) {
$buildEngagementLevel = TRUE;
- $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'option_url' => NULL));
+ $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search'));
// Add survey result field.
$optionGroups = CRM_Campaign_BAO_Survey::getResultSets( 'name' );
break;
case 'contact_type':
if ($context == 'search') {
- // CRM-15495 - EntityRef filters expect this format
+ // CRM-15495 - EntityRef filters and basic search forms expect this format
+ // FIXME: Search builder does not
return CRM_Contact_BAO_ContactType::getSelectElements();
}
break;
return array($numContactsAdded, $numContactsNotAdded);
}
+
+ /**
+ * Get options for a given field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context : @see CRM_Core_DAO::buildOptionsContext
+ * @param Array $props : whatever is known about this dao object
+ *
+ * @return Array|bool
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $params = array();
+
+ $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
+ // Sort group list by hierarchy
+ // TODO: This will only work when api.entity is "group_contact". What about others?
+ if (($fieldName == 'group' || $fieldName == 'group_id') && ($context == 'search' || $context == 'create')) {
+ $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE);
+ }
+
+ return $options;
+ }
}
);
}
+ // add select for groups
if (!empty($searchOptions['groups'])) {
- // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
- $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, ' ', TRUE);
-
- // add select for groups
- $group = array('' => ts('- any group -')) + $groupHierarchy;
- $this->add('select', 'group', ts('in'), $group, FALSE, array('class' => 'crm-select2'));
+ $this->addSelect('group', array('entity' => 'group_contact', 'label' => ts('in'), 'context' => 'search', 'placeholder' => ts('- any group -')));
}
if (!empty($searchOptions['tags'])) {
// tag criteria
if (!empty($this->_tag)) {
- $tag = array('' => ts('- any tag -')) + $this->_tag;
- $this->add('select', 'tag', ts('with'), $tag, FALSE, array('class' => 'crm-select2'));
+ $this->addSelect('tag', array('entity' => 'entity_tag', 'label' => ts('with'), 'context' => 'search', 'placeholder' => ts('- any tag -')));
}
}
$form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
//CRM-6138 Preferred Language
- $form->addSelect('preferred_language', array('class' => 'twenty', 'option_url' => NULL));
+ $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
// Phone search
$form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
$form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
}
- $form->addSelect('world_region', array('entity' => 'address', 'placeholder' => ts('- any -'), 'option_url' => NULL));
+ $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
// select for location type
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
// CRM-13848
$form->addSelect('financial_type_id',
- array('entity' => 'contribution', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')
);
$form->add('select', 'contribution_page_id',
array(
'entity' => 'contribution_soft',
'field' => 'soft_credit_type_id',
- 'multiple' => 'multiple',
- 'option_url' => NULL,
- 'placeholder' => ts('- any -')
+ 'multiple' => TRUE,
+ 'context' => 'search',
)
);
$tags['status'] = TRUE;
return $tags;
}
+
+ /**
+ * Get options for a given field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context : @see CRM_Core_DAO::buildOptionsContext
+ * @param Array $props : whatever is known about this dao object
+ *
+ * @return Array|bool
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $params = array();
+
+ $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
+ // Output tag list as nested hierarchy
+ // TODO: This will only work when api.entity is "entity_tag". What about others?
+ if (($fieldName == 'tag' || $fieldName == 'tag_id') && ($context == 'search' || $context == 'create')) {
+ $options = CRM_Core_BAO_Tag::getTags('civicrm_contact', CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+ }
+
+ return $options;
+ }
}
* - option_url - path to edit this option list - usually retrieved automatically - set to NULL to disable link
* - placeholder - set to NULL to disable
* - multiple - bool
+ * - context - @see CRM_Core_DAO::buildOptionsContext
* @param bool $required
* @throws CRM_Core_Exception
* @return HTML_QuickForm_Element
$options = $props['options'];
}
else {
- $info = civicrm_api3($props['entity'], 'getoptions', array('field' => $props['field']));
+ $info = civicrm_api3($props['entity'], 'getoptions', $props);
$options = $info['values'];
}
if (!array_key_exists('placeholder', $props)) {
- $props['placeholder'] = $required ? ts('- select -') : ts('- none -');
+ $props['placeholder'] = $required ? ts('- select -') : CRM_Utils_Array::value('context', $props) == 'search' ? ts('- any -') : ts('- none -');
}
// Handle custom field
if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
list(, $id) = explode('_', $name);
$label = isset($props['label']) ? $props['label'] : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'label', $id);
$gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id);
- $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid);
+ if (CRM_Utils_Array::value('context', $props) != 'search') {
+ $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid);
+ }
}
// Core field
else {
}
}
$label = isset($props['label']) ? $props['label'] : $fieldSpec['title'];
- $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : $props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec);
+ if (CRM_Utils_Array::value('context', $props) != 'search') {
+ $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : $props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec);
+ }
}
$props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2";
$props['data-api-entity'] = $props['entity'];
$props['data-api-field'] = $props['field'];
- CRM_Utils_Array::remove($props, 'label', 'entity', 'field', 'option_url', 'options');
+ CRM_Utils_Array::remove($props, 'label', 'entity', 'field', 'option_url', 'options', 'context');
return $this->add('select', $name, $label, $options, $required, $props);
}