* True if used for search else false.
* @param string $label
* Label for custom field.
+ *
+ * @return HTML_QuickForm_Element|null
*/
public static function addQuickFormElement(
&$qf,
) {
$field = self::getFieldObject($fieldId);
$widget = $field->html_type;
+ $element = NULL;
// Custom field HTML should indicate group+field name
$groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
$qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
}
else {
- $element = &$qf->add('text', $elementName, $label,
+ $element = $qf->add('text', $elementName, $label,
$field->attributes,
$useRequired && !$search
);
if ($field->text_length) {
$attributes .= ' maxlength=' . $field->text_length;
}
- $element = &$qf->add('textarea',
+ $element = $qf->add('textarea',
$elementName,
$label,
$attributes,
$qf->add('datepicker', $elementName . '_to', NULL, $attr + array('placeholder' => ts('To')), FALSE, $params);
}
else {
- $qf->add('datepicker', $elementName, $label, $attr, $useRequired && !$search, $params);
+ $element = $qf->add('datepicker', $elementName, $label, $attr, $useRequired && !$search, $params);
}
break;
foreach ($options as $v => $l) {
$choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
}
- $group = $qf->addGroup($choice, $elementName, $label);
+ $element = $qf->addGroup($choice, $elementName, $label);
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
else {
- $group->setAttribute('allowClear', TRUE);
+ $element->setAttribute('allowClear', TRUE);
}
break;
if (empty($selectAttributes['multiple'])) {
$options = array('' => $placeholder) + $options;
}
- $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes);
+ $element = $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes);
// Add and/or option for fields that store multiple values
if ($search && self::isSerialized($field)) {
break;
case 'AdvMulti-Select':
- $include =& $qf->addElement(
+ $element = $qf->addElement(
'advmultiselect',
$elementName,
$label, $options,
)
);
- $include->setButtonAttributes('add', array('value' => ts('Add >>')));
- $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
+ $element->setButtonAttributes('add', array('value' => ts('Add >>')));
+ $element->setButtonAttributes('remove', array('value' => ts('<< Remove')));
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
foreach ($options as $v => $l) {
$check[] = &$qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal));
}
- $qf->addGroup($check, $elementName, $label);
+ $element = $qf->addGroup($check, $elementName, $label);
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
case 'File':
// we should not build upload file in search mode
if ($search) {
- return;
+ return NULL;
}
- $qf->add(
+ $element = $qf->add(
strtolower($field->html_type),
$elementName,
$label,
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
- $qf->add('wysiwyg', $elementName, $label, $attributes, $search);
+ $element = $qf->add('wysiwyg', $elementName, $label, $attributes, $search);
break;
case 'Autocomplete-Select':
if ($field->data_type == 'ContactReference') {
$attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge';
$attributes['data-api-entity'] = 'contact';
- $qf->add('text', $elementName, $label, $attributes,
- $useRequired && !$search
- );
+ $element = $qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
$urlParams = "context=customfield&id={$field->id}";
'params' => array('option_group_id' => $field->option_group_id),
),
);
- $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
+ $element = $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
}
$qf->assign('customUrls', $customUrls);
if ($field->is_view && !$search) {
$qf->freeze($elementName);
}
+ return $element;
}
/**
* @return HTML_QuickForm_Element
*/
public function addField($name, $props = array(), $required = FALSE) {
- // TODO: Handle custom field
- if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
- throw new Exception("Custom fields are not supported by the addField method. ");
- }
// Resolve context.
if (!isset($props['context'])) {
$props['context'] = $this->getDefaultContext();
if (!isset($props['action'])) {
$props['action'] = $this->getApiAction();
}
- // Get field metadata.
+
+ // Handle custom fields
+ if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
+ $fieldId = (int) substr($name, 7);
+ return CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $fieldId, FALSE, $required, $props['context'] == 'search', CRM_Utils_Array::value('label', $props));
+ }
+
+ // Core field - get metadata.
$fieldSpec = civicrm_api3($props['entity'], 'getfield', $props);
$fieldSpec = $fieldSpec['values'];
$label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL);