use addfield in addressForm
authorTim Mallezie <tim.mallezie@chiro.be>
Fri, 8 May 2015 16:14:08 +0000 (18:14 +0200)
committerTim Mallezie <tim.mallezie@chiro.be>
Fri, 8 May 2015 16:14:08 +0000 (18:14 +0200)
CRM/Contact/Form/Edit/Address.php
CRM/Core/Form.php
templates/CRM/Contact/Form/Edit/Address/city_postal_code.tpl
xml/schema/Core/Address.xml

index f1fd17bb52d781142951de73ff5d6e08d24cfdfc..b6cdd6b7f938157bda5aac3d89b17d4df3d3a15e 100644 (file)
@@ -72,75 +72,60 @@ class CRM_Contact_Form_Edit_Address {
     }
 
     //make location type required for inline edit
-    $form->addSelect("address[$blockId][location_type_id]", array(
-        'entity' => 'address',
-        'class' => 'eight',
-      ) + $js, $inlineEdit);
+    $form->addField("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     }
 
-    $form->addElement(
-      'checkbox',
-      "address[$blockId][is_primary]",
-      ts('Primary location for this contact'),
-      ts('Primary location for this contact'),
-      $js
-    );
+    $form->addField(
+      "address[$blockId][is_primary]", array(
+        'entity' => 'address',
+        'label' => ts('Primary location for this contact'),
+        'text' => ts('Primary location for this contact')) + $js);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
 
-    $form->addElement(
-      'checkbox',
-      "address[$blockId][is_billing]",
-      ts('Billing location for this contact'),
-      ts('Billing location for this contact'),
-      $js
-    );
+    $form->addField(
+      "address[$blockId][is_billing]", array(
+        'entity' => 'address',
+        'label' => ts('Primary location for this contact'),
+        'text' => ts('Primary location for this contact')) + $js);
 
     // hidden element to store master address id
-    $form->addElement('hidden', "address[$blockId][master_id]");
-
+    $form->addField("address[$blockId][master_id]", array('entity' => 'address', 'type' => 'hidden'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
       'address_options', TRUE, NULL, TRUE
     );
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
 
     $elements = array(
-      'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL),
-      'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL),
-      'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL),
-      'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL),
-      'city' => array(ts('City'), $attributes['city'], NULL),
-      'postal_code' => array(
-        ts('Zip / Postal Code'),
-        array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')),
-        NULL,
-      ),
-      'postal_code_suffix' => array(
-        ts('Postal Code Suffix'),
-        array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'),
-        NULL,
-      ),
-      'country_id' => array(ts('Country'), $attributes['country_id'], 'country'),
-      'state_province_id' => array(ts('State/Province'), $attributes['state_province_id'], NULL),
-      'county_id' => array(ts('County'), $attributes['county_id'], NULL),
-      'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 12), NULL),
-      'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 12), NULL),
-      'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL),
-      'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL),
-      'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL),
+      'address_name',
+      'street_address',
+      'supplemental_address_1',
+      'supplemental_address_2',
+      'city',
+      'postal_code',
+      'postal_code_suffix',
+      'country_id',
+      'state_province_id',
+      'county_id',
+      'geo_code_1',
+      'geo_code_2',
+      'street_number',
+      'street_name',
+      'street_unit',
     );
 
-    foreach ($elements as $name => $v) {
-      list($title, $attributes, $select) = $v;
-
+    foreach ($elements as $name) {
+      //Remove id from name, to allow comparison against enabled addressOtions.
       $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
+      // Skip fields which are not enabled in the address options.
       if (empty($addressOptions[$nameWithoutID])) {
         $continue = TRUE;
+        //Don't skip street parsed fields when parsing is enabled.
         if (in_array($nameWithoutID, array(
             'street_number',
             'street_name',
@@ -153,35 +138,11 @@ class CRM_Contact_Form_Edit_Address {
           continue;
         }
       }
-
-      //build normal select if country is not present in address block
-      if ($name == 'state_province_id' && !$addressOptions['country']) {
-        $select = 'stateProvince';
+      if ($name == 'address_name') {
+        $name = 'name';
       }
 
-      if (!$select) {
-        if ($name == 'state_province_id' || $name == 'county_id') {
-          $form->addChainSelect("address[$blockId][$name]");
-        }
-        else {
-          if ($name == 'address_name') {
-            $name = 'name';
-          }
-
-          $form->addElement('text',
-            "address[$blockId][$name]",
-            $title,
-            $attributes
-          );
-        }
-      }
-      else {
-        $form->addElement('select',
-          "address[$blockId][$name]",
-          $title,
-          array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select()
-        );
-      }
+      $form->addField("address[$blockId][$name]", array('entity' => 'address'));
     }
 
     $entityId = NULL;
index 4bddc368b013d3a9baf264504e2140cc7709eea9..7badffb79ba1a5db4a1cd1bee8c095eee22b02fb 100644 (file)
@@ -1294,7 +1294,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
 
       //case 'AdvMulti-Select':
       case 'CheckBox':
-        $this->add('checkbox', $name, $label, NULL, $required);
+        $text = isset($props['text']) ? $props['text'] : NULL;
+        unset($props['text']);
+        $this->addElement('checkbox', $name, $label, $text, $props);
         break;
 
       case 'File':
index 210a510a2b51ddebb4f812ad41510b457546451c..d30647c8556f7c889d6c1692083e3773730e74e9 100644 (file)
     {/if}
     {if !empty($form.address.$blockId.postal_code)}
        <td>
-          {$form.address.$blockId.postal_code.label}{if !empty($form.address.$blockId.postal_code_suffix)}&nbsp;<span>{ts}Suffix{/ts}</span>{/if}<br />
+          {$form.address.$blockId.postal_code.label}<br />
           {$form.address.$blockId.postal_code.html}&nbsp;&nbsp;
           {if !empty($form.address.$blockId.postal_code_suffix)}
+          <td>
+            {$form.address.$blockId.postal_code_suffix.label}<br/>
             {$form.address.$blockId.postal_code_suffix.html} {help id="id-postal-code-suffix" file="CRM/Contact/Form/Contact.hlp"}
+          <td>
           {/if}
        </td>
     {/if}
index cc6af4895bc9b7af929c95d9f5942e4d76df1c4d..d23de1c1553cac94ce534b22156276c53295f51c 100644 (file)
@@ -60,6 +60,9 @@
     <default>0</default>
     <comment>Is this the primary address.</comment>
     <add>2.0</add>
+    <html>
+      <type>CheckBox</type>
+    </html>
   </field>
   <index>
     <name>index_is_primary</name>
@@ -73,6 +76,9 @@
     <default>0</default>
     <comment>Is this the billing address.</comment>
     <add>2.0</add>
+    <html>
+      <type>CheckBox</type>
+    </html>
   </field>
   <index>
     <name>index_is_billing</name>
@@ -92,6 +98,9 @@
       delivery, etc.).
     </comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_number</name>
     <export>true</export>
     <comment>Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_number_suffix</name>
     <comment>Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A
     </comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_number_predirectional</name>
     <length>8</length>
     <comment>Directional prefix, e.g. SE Main St, SE is the prefix.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_name</name>
     <export>true</export>
     <comment>Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <index>
     <name>index_street_name</name>
     <length>8</length>
     <comment>St, Rd, Dr, etc.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_number_postdirectional</name>
     <length>8</length>
     <comment>Directional prefix, e.g. Main St S, S is the suffix.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>street_unit</name>
     <export>true</export>
     <comment>Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>supplemental_address_1</name>
     <dataPattern>/unit|ap(ar)?t(ment)?\s(\d|\w)+/i</dataPattern>
     <comment>Supplemental Address Information, Line 1</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>supplemental_address_2</name>
     <dataPattern>/unit|ap(ar)?t(ment)?\s(\d|\w)+/i</dataPattern>
     <comment>Supplemental Address Information, Line 2</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>supplemental_address_3</name>
     <length>96</length>
     <comment>Supplemental Address Information, Line 3</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>city</name>
     <dataPattern>/^[A-Za-z]+(\.?)(\s?[A-Za-z]+){0,2}$/</dataPattern>
     <comment>City, Town or Village Name.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <index>
     <name>index_city</name>
   </foreignKey>
   <field>
     <name>postal_code_suffix</name>
-    <title>Postal Code Suffix</title>
+    <title>Zip / Postal Code Suffix</title>
     <type>varchar</type>
     <length>12</length>
     <import>true</import>
     <dataPattern>/\d?\d{4}(-\d{4})?/</dataPattern>
     <comment>Store the suffix, like the +4 part in the USPS system.</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>postal_code</name>
-    <title>Postal Code</title>
+    <title>Zip / Postal Code</title>
     <type>varchar</type>
     <length>12</length>
     <import>true</import>
       validation.
     </comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>usps_adc</name>
     <headerPattern>/geo/i</headerPattern>
     <comment>Latitude</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+      <size>9</size>
+    </html>
   </field>
   <field>
     <name>geo_code_2</name>
     <import>true</import>
     <headerPattern>/geo/i</headerPattern>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+      <size>9</size>
+    </html>
   </field>
   <field>
     <name>manual_geo_code</name>
     <default>0</default>
     <comment>Is this a manually entered geo code</comment>
     <add>4.3</add>
+    <html>
+      <type>CheckBox</type>
+    </html>
   </field>
   <field>
     <name>timezone</name>
     <length>8</length>
     <comment>Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6".</comment>
     <add>1.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>name</name>
     <headerPattern>/^location|(l(ocation\s)?name)$/i</headerPattern>
     <dataPattern>/^\w+$/</dataPattern>
     <add>2.1</add>
+    <html>
+      <type>Text</type>
+    </html>
   </field>
   <field>
     <name>master_id</name>