//prefix
$prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
if (isset($nameFields['Prefix']) && !empty($prefix)) {
- $form->addField('prefix_id', array('class' => 'eight', 'placeholder' => ' '));
+ $form->addField('prefix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Prefix')));
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
// suffix
$suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
if (isset($nameFields['Suffix']) && $suffix) {
- $form->addSelect('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix')));
+ $form->addField('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix')));
}
}
// job title
// override the size for UI to look better
$attributes['job_title']['size'] = 30;
- $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
-
+ //$form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
+ $form->addField('job_title', array('size' => 30));
//Current Employer Element
$props = array(
'api' => array('params' => array('contact_type' => 'Organization')),
throw new Exception("Cannot determine default entity. The form class should implement getDefaultEntity().");
}
+ /**
+ * Classes extending CRM_Core_Form should implement this method.
+ *
+ * TODO: Merge with CRM_Core_DAO::buildOptionsContext($context) and add validation.
+ * @throws Exception
+ */
+ public function getDefaultContext() {
+ throw new Exception("Cannot determine default context. The form class should implement getDefaultContext().");
+ }
+
/**
* Adds a select based on field metadata.
* TODO: This could be even more generic and widget type (select in this case) could also be read from metadata
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();
+ }
// Resolve entity.
if (!isset($props['entity'])) {
$props['entity'] = $this->getDefaultEntity();
$label = isset($props['label']) ? $props['label'] : $fieldSpec['title'];
$widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type'];
-
- if ($widget == 'TextArea' && CRM_Utils_Array::value('context', $props) == 'search') {
+ if ($widget == 'TextArea' && $props['context'] == 'search') {
$widget = 'Text';
}
// The placeholder is only used for select-elements.
if (!array_key_exists('placeholder', $props)) {
- $props['placeholder'] = $required ? ts('- select -') : CRM_Utils_Array::value('context', $props) == 'search' ? ts('- any -') : ts('- none -');
+ $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -');
}
- if (CRM_Utils_Array::value('context', $props) == 'search' || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) {
+ if ($props['context'] == 'search' || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) {
$widget = 'Select';
}
$props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2";
- if (CRM_Utils_Array::value('context', $props) == 'search' || strpos($widget, 'Multi') !== FALSE) {
+ if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) {
$props['class'] .= ' huge';
$props['multiple'] = 'multiple';
}
// Add data for popup link.
- if (CRM_Utils_Array::value('context', $props) != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
+ if ($props['context'] != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
$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['data-api-entity'] = $props['entity'];
$props['data-api-field'] = $props['field'];