From 33fa033ceb9f8fbe3705a791a7c0643e1ecda941 Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Sun, 29 Mar 2015 16:45:33 +0200 Subject: [PATCH] This converts CRM_Contact_Form_Contact to use addField. This cleans up the select element, and adds support for file elements. --- CRM/Contact/Form/Contact.php | 17 ++++++++--------- CRM/Core/Form.php | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index c6a7d72f98..b580b76a48 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -786,13 +786,13 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { // subtype is a common field. lets keep it here $subtypes = CRM_Contact_BAO_Contact::buildOptions('contact_sub_type', 'create', array('contact_type' => $this->_contactType)); if (!empty($subtypes)) { - $sel = $this->add('select', 'contact_sub_type', ts('Contact Type'), - $subtypes, FALSE, - array( - 'id' => 'contact_sub_type', - 'multiple' => 'multiple', - 'class' => $buildCustomData . ' crm-select2', - ) + $this->addField('contact_sub_type', array( + 'label' => ts('Contact Type'), + 'options' => $subtypes, + 'class' => $buildCustomData, + 'multiple' => 'multiple', + 'options-url' => FALSE, + ) ); } @@ -818,8 +818,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { CRM_Contact_Form_Location::buildQuickForm($this); // add attachment - $this->addElement('file', 'image_URL', ts('Browse/Upload Image'), 'size=30 maxlength=60'); - $this->addUploadElement('image_URL'); + $this->addField('image_URL', array('type' => 'File', 'size' => '30', 'maxlength' => '60', 'label' => ts('Browse/Upload Image'))); // add the dedupe button $this->addElement('submit', diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index bd6205f91f..8770b9841d 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1201,6 +1201,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // Fetch options from the api unless passed explicitly. if (isset($props['options'])) { $options = $props['options']; + // Else this get passed to the form->add method. + unset($props['options']); } else { $options = $fieldSpec['options']; @@ -1221,10 +1223,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } // Add data for popup link. - if ($props['context'] != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) { + if ((isset($props['options-url']) && $props['options-url']) && ($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['name']; + if (isset($props['options-url'])) { + unset($props['options-url']); + } } } $props += CRM_Utils_Array::value('html', $fieldSpec, array()); @@ -1249,13 +1254,22 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if (empty($props['multiple'])) { $options = array('' => $props['placeholder']) + $options; } - $this->add('select', $name, $label, $options, $required, $props); + $props += array('required' => $required); + $this->addElement('select', $name, $label, $options, $props); // TODO: Add and/or option for fields that store multiple values break; //case 'AdvMulti-Select': //case 'CheckBox': - //case 'File': + case 'File': + // We should not build upload file in search mode. + if (isset($props['context']) && $props['context'] == 'search') { + return; + } + $this->addElement('file', $name, $label, $props, $required); + $this->addUploadElement($name); + break; + //case 'RichTextEditor': //TODO: Add javascript template for wysiwyg. case 'Autocomplete-Select': -- 2.25.1