Merge pull request #5513 from mallezie/contact-select-file-16178
authorcolemanw <coleman@civicrm.org>
Sat, 11 Apr 2015 12:50:29 +0000 (08:50 -0400)
committercolemanw <coleman@civicrm.org>
Sat, 11 Apr 2015 12:50:29 +0000 (08:50 -0400)
CRM_Contact_Form_Contact to use addField CRM-16178

CRM/Contact/Form/Contact.php
CRM/Core/Form.php
xml/schema/Contact/Contact.xml

index 3698ec12b8c8775a3a0e5e5a5eae26af3e49fe72..95c265587d0732fe66899f88555180efc198eb51 100644 (file)
@@ -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('maxlength' => '60', 'label' => ts('Browse/Upload Image')));
 
     // add the dedupe button
     $this->addElement('submit',
index b50d8b648063303284eb3d7db9d42b1a29284c82..c6079b34c4688d79b53c405c892274309f4ca4bd 100644 (file)
@@ -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'];
@@ -1219,25 +1221,33 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
         $props['class'] .= ' huge';
         $props['multiple'] = 'multiple';
       }
+      // Set default options-url value.
+      if ((!isset($props['options-url']))) {
+        $props['options-url'] = TRUE;
+      }
 
       // 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());
     CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type');
+    // TODO: refactor switch statement, to seperate methods.
     switch ($widget) {
       case 'Text':
       case 'Link':
         //TODO: Autodetect ranges
-        $this->addElement('text', $name, $label, $props, $required);
+        $this->add('text', $name, $label, $props, $required);
         break;
 
       case 'hidden':
-        $this->addElement('hidden', $name, $label, $props);
+        $this->add('hidden', $name, $label, $props, $required);
         break;
 
       //case 'TextArea':
@@ -1255,12 +1265,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
 
       //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->add('file', $name, $label, $props, $required);
+        $this->addUploadElement($name);
+        break;
+
       //case 'RichTextEditor':
       //TODO: Add javascript template for wysiwyg.
       case 'Autocomplete-Select':
       case 'EntityRef':
-        $this->addEntityRef($name, $label, $props);
+        $this->addEntityRef($name, $label, $props, $required);
         break;
 
       // Check datatypes of fields
index f90a154c0ba8d375976bbfdea223baec3c27bd1f..d8c78e8d369c1c11bf6563a9b94cb933b2514b80 100644 (file)
     <comment>optional URL for preferred image (photo, logo, etc.) to display for this contact.</comment>
     <add>1.1</add>
     <html>
-      <type>Text</type>
+      <type>File</type>
+      <size>BIG</size>
     </html>
   </field>
   <field>