if (!isset($props['field'])) {
$props['field'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name;
}
- $info = civicrm_api3($props['entity'], 'getoptions', array(
- 'field' => $props['field'],
- 'options' => array('metadata' => array('fields'))
- )
- );
- $options = $info['values'];
+ // Fetch options from the api unless passed explicitly
+ if (isset($props['options'])) {
+ $options = $props['options'];
+ }
+ else {
+ $info = civicrm_api3($props['entity'], 'getoptions', array('field' => $props['field']));
+ $options = $info['values'];
+ }
if (!array_key_exists('placeholder', $props)) {
$props['placeholder'] = $required ? ts('- select -') : ts('- none -');
}
}
// Core field
else {
- foreach($info['metadata']['fields'] as $uniqueName => $fieldSpec) {
+ $info = civicrm_api3($props['entity'], 'getfields');
+ foreach($info['values'] as $uniqueName => $fieldSpec) {
if (
$uniqueName === $props['field'] ||
CRM_Utils_Array::value('name', $fieldSpec) === $props['field'] ||
$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');
+ CRM_Utils_Array::remove($props, 'label', 'entity', 'field', 'option_url', 'options');
return $this->add('select', $name, $label, $options, $required, $props);
}
}
CRM_Activity_BAO_Activity::create($activityParams);
}
+
+ /**
+ * 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('condition' => array());
+
+ if ($fieldName == 'status_id' && $context != 'validate') {
+ // Get rid of cart-related option if disabled
+ // FIXME: Why does this option even exist if cart is disabled?
+ if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) {
+ $params['condition'][] = "name <> 'Pending in cart'";
+ }
+ }
+
+ return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+ }
}
$notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
$this->assign('notificationStatusIds', $notificationStatusIds);
- $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
- $this->addSelect('status_id', $checkCancelledJs + array('option_url' => 'civicrm/admin/participant_status'), TRUE);
+ $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
- $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
- 'enable_cart'
- );
- $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
- $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
- $this->assign('enableCart', $enableCart);
- $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
- $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
+ // Only show refund status when editing
+ if ($this->_action & CRM_Core_Action::ADD) {
+ $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
+ if ($pendingRefundStatusId) {
+ unset($statusOptions[$pendingRefundStatusId]);
+ }
+ }
+
+ $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
$this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
var $form = $('form.{/literal}{$form.formClass}{literal}');
- // don't show cart related statuses if it's disabled
- {/literal}{if !$enableCart}{literal}
- var pendingInCartStatusId = {/literal}{$pendingInCartStatusId}{literal};
- $("#status_id option[value='" + pendingInCartStatusId + "']").remove();
- {/literal}{/if}{literal}
-
- {/literal}{if $action eq 1}{literal}
- var pendingRefundStatusId = {/literal}{$pendingRefundStatusId}{literal};
- $("#status_id option[value='" + pendingRefundStatusId + "']").remove();
- {/literal}{/if}{literal}
-
// Handle event selection
$('#event_id', $form).change(function() {
var eventId = $(this).val();