use addField in communication preferences form
authorTim Mallezie <tim.mallezie@chiro.be>
Tue, 12 May 2015 16:05:09 +0000 (18:05 +0200)
committerTim Mallezie <tim.mallezie@chiro.be>
Thu, 14 May 2015 06:27:49 +0000 (08:27 +0200)
CRM/Contact/Form/Edit/CommunicationPreferences.php
CRM/Core/Form.php
templates/CRM/Contact/Form/Edit/CommunicationPreferences.tpl
xml/schema/Contact/Contact.xml

index beb88b74f816bce8b7e52330c06db39b333ba776..f3f3070cf2ec75f8cdaa87f9aab55077127fc0b4 100644 (file)
@@ -67,16 +67,15 @@ class CRM_Contact_Form_Edit_CommunicationPreferences {
     foreach ($privacyOptions as $name => $label) {
       $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
     }
-    $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;');
+    $form->addGroup($privacy, 'privacy', ts('Privacy'), '&nbsp;<br/>');
 
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
     foreach ($comm as $value => $title) {
       $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
     }
-    $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
-
-    $form->addSelect('preferred_language');
+    $form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup'));
+    $form->addField('preferred_language', array('entity' => 'contact'));
 
     if (!empty($privacyOptions)) {
       $commPreference['privacy'] = $privacyOptions;
@@ -88,21 +87,11 @@ class CRM_Contact_Form_Edit_CommunicationPreferences {
     //using for display purpose.
     $form->assign('commPreference', $commPreference);
 
-    $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
-    $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
+    $form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format')));
 
-    $communicationStyleOptions = array();
-    $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE));
-    foreach ($communicationStyle as $key => $var) {
-      $communicationStyleOptions[$key] = $form->createElement('radio', NULL,
-        ts('Communication Style'), $var, $key,
-        array('id' => "civicrm_communication_style_{$var}_{$key}")
-      );
-    }
-    if (!empty($communicationStyleOptions)) {
-      $form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style'));
-    }
+    $form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)')));
 
+    $form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup'));
     //check contact type and build filter clause accordingly for greeting types, CRM-4575
     $greetings = self::getGreetingFields($form->_contactType);
 
index 822792605cba3f94e4e66ff03b4c5042ec4e3378..43e60e28c1be4cc0f9431df476eeeb76f63a5246 100644 (file)
@@ -900,6 +900,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     return $group;
   }
 
+  /**
+   * @param string $name
+   * @param $title
+   * @param $values
+   * @param array $attributes
+   * @param null $separator
+   * @param bool $required
+   *
+   * @return HTML_QuickForm_group
+   */
+  public function &addRadioGroup($name, $title, $values, $attributes = array(), $separator = NULL, $required = FALSE) {
+    return $this->addRadio($name, $title, $values, $attributes, $separator, $required);
+  }
+
   /**
    * @param int $id
    * @param $title
@@ -976,6 +990,28 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     }
   }
 
+
+  /**
+   * @param int $id
+   * @param $title
+   * @param $values
+   * @param null $other
+   * @param null $attributes
+   * @param null $required
+   * @param null $javascriptMethod
+   * @param string $separator
+   * @param bool $flipValues
+   */
+  public function addCheckBoxGroup(
+  $id, $title, $values, $other = NULL, $attributes = NULL, $required = NULL,
+  $javascriptMethod = NULL, $separator = '<br />', $flipValues = FALSE
+  ) {
+    $this->addCheckBox(
+        $id, $title, $values, $other,
+        $attributes, $required, $javascriptMethod, $separator, $flipValues
+    );
+  }
+
   public function resetValues() {
     $data = $this->controller->container();
     $data['values'][$this->_name] = array();
@@ -1197,7 +1233,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
           'Select Country',
           'Multi-Select Country',
           'AdvMulti-Select',
-          'CheckBox',
+          'CheckBoxGroup',
+          'RadioGroup',
           'Radio',
     )));
 
@@ -1296,6 +1333,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
         // TODO: Add and/or option for fields that store multiple values
         break;
 
+      case 'CheckBoxGroup':
+        $this->addCheckBoxGroup($name, $label, array_flip($options), $required, $props);
+        break;
+
+      case 'RadioGroup':
+        $this->addRadioGroup($name, $label, $options, $props, NULL, $required);
+        break;
+
       //case 'AdvMulti-Select':
       case 'CheckBox':
         $text = isset($props['text']) ? $props['text'] : NULL;
index c4116b4d40bd58f9d1ed024f7db91b17b7eec58c..4ec52af45bd7c2a5a389a51edef5d3e14b4cd686 100644 (file)
             {/if}
         </tr>
         <tr>
-            {foreach key=key item=item from=$commPreference}
-                <td>
-                    <br /><span class="label">{$form.$key.label}</span> {help id="id-$key" file="CRM/Contact/Form/Contact.hlp"}
-                    {foreach key=k item=i from=$item}
-                     <br />{$form.$key.$k.html}
-                    {/foreach}
-                </td>
-            {/foreach}
-                 <td>
-                     <br /><span class="label">{$form.preferred_language.label}</span>
-                     <br />{$form.preferred_language.html}
-                </td>
+          {foreach key=key item=item from=$commPreference}
+            <td>
+              <br/><span class="label">{$form.$key.label}</span> {help id="id-$key" file="CRM/Contact/Form/Contact.hlp"}
+              <br/>{$form.$key.html}
+            </td>
+          {/foreach}
+          <td>
+            <br/><span class="label">{$form.preferred_language.label}</span>
+            <br/>{$form.preferred_language.html}
+          </td>
         </tr>
         <tr>
             <td>{$form.is_opt_out.html} {$form.is_opt_out.label} {help id="id-optOut" file="CRM/Contact/Form/Contact.hlp"}</td>
index 06f6b50d67a40cbd517fa484b28e988f9a4aef7e..4cddbcf7afd1dc6738b8ac4aaba43fd5dc8115fe 100644 (file)
     <export>true</export>
     <comment>Communication style (e.g. formal vs. familiar) to use with this contact. FK to communication styles in civicrm_option_value.</comment>
     <add>4.4</add>
+    <html>
+      <type>Select</type>
+    </html>
   </field>
   <index>
     <name>index_communication_style_id</name>