From: Tim Mallezie Date: Tue, 24 Mar 2015 15:39:50 +0000 (+0100) Subject: change suffix field, add defaultContext method X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1ae720b33d4b557032defc3877df73386692244f;p=civicrm-core.git change suffix field, add defaultContext method --- diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 65df284ebd..c6a7d72f98 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -134,6 +134,13 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { return 'Contact'; } + /** + * Explicitly declare the form context. + */ + public function getDefaultContext() { + return 'create'; + } + /** * Build all the data structures needed to build the form. * diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index f21c3228fa..bc13a3843a 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -64,7 +64,7 @@ class CRM_Contact_Form_Edit_Individual { //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'); @@ -91,7 +91,7 @@ class CRM_Contact_Form_Edit_Individual { // 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'))); } } @@ -104,8 +104,8 @@ class CRM_Contact_Form_Edit_Individual { // 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')), diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index daaa95bbfc..728ee69943 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1039,6 +1039,16 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 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 @@ -1129,7 +1139,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 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(); @@ -1153,8 +1166,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $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'; } @@ -1182,20 +1194,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // 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'];